Prashanth K.A
Prashanth K.A

Reputation: 21

React redux, component re-rendering

I have a react functional component, I want the component to re-render when the state coming from the store is updated.

I want the component to re-render when the value of logoPic variable is updated. The value is coming from the redux store(fetched using useSelector hook).

const { user: { downloadLink, bucketName, timeStamp, logoPic, organizationName, logoName, }, } = useSelector((state) => state.loginReducer);

Upvotes: 2

Views: 40

Answers (1)

Tushar Shahi
Tushar Shahi

Reputation: 20626

A component subscribed to a redux store re-renders when there is an update to the store and the value returned from the selector is updated.

Currently you are subscribing to (state) => state.loginReducer, so whenever loginReducer updates, the component rerenders.

Update your selector to:

const logoPic = useSelector((state) => state.loginReducer.user.logoPic);

Upvotes: 0

Related Questions