I have my state in redux, and i have a recuring function that at the start of every recurrance needs to look up an state object, everything works well
except to keep within the hooks rules, i have to load the whole state into the component which has the recurring function using const state = useSelector(state => state)
then in the loop use const someVariable = state['someValue']
this works at the moment without issue, but i am concerned that as my appication grows so will the state, and i am concerned this is a bad idea as loading in a massive state could cause performance issues.
a few questions, is this a legit concern? or am i being overly causous?
one option would be to have all the objects related to this inside a base object mean i could only refence this part of state,however i don't think i can do this as they have seperate reducers and therefore have different state objects
the other is find a better was to select inside the the loop, but i don't know how to do that either, i know i can't use const selector = useSelector, because that throws the rules of hooks error
the state is used by multiple hooks, but the state isn't going to change without some user action
typically with redux there is only one state instance. so it can be passed around with no cost. normally you would use mapStateToProps via connect() to map the part of state your component is interested in.
redux hooks are an alternative to this, the useSelector() does the mapping. The caller of the component should supply this hook via a prop, or the component is too tightly coupled to the state.
Participant
1861 Points
2836 Posts
help with redux issue
Oct 11, 2019 03:04 AM|EnenDaveyBoy|LINK
Hi
I have my state in redux, and i have a recuring function that at the start of every recurrance needs to look up an state object, everything works well
except to keep within the hooks rules, i have to load the whole state into the component which has the recurring function using const state = useSelector(state => state)
then in the loop use const someVariable = state['someValue']
this works at the moment without issue, but i am concerned that as my appication grows so will the state, and i am concerned this is a bad idea as loading in a massive state could cause performance issues.
a few questions, is this a legit concern? or am i being overly causous?
one option would be to have all the objects related to this inside a base object mean i could only refence this part of state,however i don't think i can do this as they have seperate reducers and therefore have different state objects
the other is find a better was to select inside the the loop, but i don't know how to do that either, i know i can't use const selector = useSelector, because that throws the rules of hooks error
the state is used by multiple hooks, but the state isn't going to change without some user action
any thougths would be appriciated
All-Star
58194 Points
15660 Posts
Re: help with redux issue
Oct 11, 2019 08:03 PM|bruce (sqlwork.com)|LINK
typically with redux there is only one state instance. so it can be passed around with no cost. normally you would use mapStateToProps via connect() to map the part of state your component is interested in.
redux hooks are an alternative to this, the useSelector() does the mapping. The caller of the component should supply this hook via a prop, or the component is too tightly coupled to the state.
Participant
1861 Points
2836 Posts
Re: help with redux issue
Oct 12, 2019 01:45 PM|EnenDaveyBoy|LINK
thnks for the info