-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
useSetState doesn't work #107
Comments
and this works fine const useSetState = <T extends object> (initialState: T = {} as any): [T, (patch: Function | Partial<T>) => void] => {
const [state, set] = useState(initialState)
const setState = (patch) => {
if (patch instanceof Function) {
set((prevState) => {
return Object.assign({}, state, patch(prevState))
})
} else {
const newState = Object.assign({}, state, patch)
set(newState)
}
}
return [state, setState]
} |
Thanks for reporting this! Should be fixed now. |
it seems still some bugs ... maybe the better way typescript
|
This will cause problems when Passing state (Object) to child Components |
@ilovedesert001 Can you give an example? Is it because child components mutate the state object? |
check out these |
@ilovedesert001 Why do you use So in fact there is no need to use the |
@likun7981 @streamich |
@ilovedesert001 Every time, the |
@likun7981 I think this should be ti. |
These two problems is no relationship |
@likun7981 OK, sry. |
since update to react 16.8.2
useSetState doesn't work
https://streamich.github.io/react-use/?selectedKind=State%2FuseSetState&selectedStory=Demo&full=0&addons=1&stories=1&panelRight=0
The text was updated successfully, but these errors were encountered: