Skip to content
New issue

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

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

Already on GitHub? # to your account

Update init behavior #9

Closed
jamesplease opened this issue Aug 22, 2019 · 2 comments
Closed

Update init behavior #9

jamesplease opened this issue Aug 22, 2019 · 2 comments

Comments

@jamesplease
Copy link
Collaborator

jamesplease commented Aug 22, 2019

When using useReducer, init returns the state:

useReducer(reducer, initialState, () => {
  return {
    someState: true
  };
})

With the current API of this library, you must return the "internal" structure of the store:

useReducerWithSideEffects(reducer, initialState, () => {
  return {
    state: { someState: true },
    sideEffects: [] // you also must include this or else an uncaught exception will occur
  };
})

Users are unable to use Update/UpdateWithSideEffects/etc., because those don't return the correct key: they return newState rather than state.

I suggest refactoring Update/etc. to internally use the key state instead. That way, users of init can use a consistent API with this lib:

useReducerWithSideEffects(reducer, initialState, () => {
  return Update({ someState: true });
})

This change could even be released as a bug fix, I think, since it only changes non-public structures.

I'm curious to hear your thoughts on this @conorhastings !

@conorhastings
Copy link
Owner

haven't tested but esseentially something like this? #11

@jamesplease
Copy link
Collaborator Author

Resolved in 2.0.0-beta.2

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

No branches or pull requests

2 participants