Skip to content

Instantly share code, notes, and snippets.

@vcarl
Last active Oct 3, 2015
Embed
What would you like to do?

you can't get around not cloning state, part of the point of redux is that object references don't get reused, so you can do oldstate === newstate and not have to do a deep comparison

only way to get that is by using a new object to get a new reference

not every property on the state object needs to be clone (e.g. it's a shallow clone) because each reducer either returns its previous state (so no clone) or a new object if there's been a change

so if you have 100 properties on the root state object and one key changes, oldstate !== newstate, but oldstate['unchangedKey'] === newstate['unchangedKey']

So when using redux, is it totally fine to set set local component state this.setState({ editing: true }); without emitting actions?

is there a good rule of thumb when and when not to use the global store?

vcarl [6:38 PM] it’s fine to use local state

the store is for application state, component state is for UI state

application state is what page are you on, what user is logged in, what data is loaded

UI state is which radio button is selected, what value is in this textbox, is this dropdown open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment