Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
feat: simplified state update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniAkash committed Oct 18, 2020
1 parent fb9e3da commit d5c6a46
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ function useRedux(store: any, key: any) {

useEffect(() => {
const unsubscribe = store.subscribe(() => {
if (key) {
const nextState = store.getState()[key]
if (state !== nextState) {
setState(nextState)
}
} else {
setState(store.getState())
const nextState = key ? store.getState()[key] : store.getState()
if (state !== nextState) {
setState(nextState)
}
})
return () => {
Expand Down

0 comments on commit d5c6a46

Please sign in to comment.