8000 propose state returning a function that is both getter & setter by aminroosta · Pull Request #2 · PutziSan/react-factory-hooks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

propose state returning a function that is both getter & setter #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2018
Merged

propose state returning a function that is both getter & setter #2

merged 2 commits into from
Nov 28, 2018

Conversation

aminroosta
Copy link
Contributor

@PutziSan I find const [getState, setState] = useState(initialValue); a bit cumbersome to type.

I propose the following alternative.

const state = useState(initialState);
state(); // getter
state(value); // setter

This is borrowed from knockout.js style of getters & setters.

@PutziSan PutziSan merged commit 13800db into PutziSan:master Nov 28, 2018
@PutziSan
Copy link
Owner

thanks, I added another possibility and created a related issue (#3), let's see if someone wants to comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0