David C
David C

Reputation: 979

Where to perform action with update in React + React Redux?

Let's say I have a music component connected to the "play" prop in the redux store.

When "play" is updated, I would like to update the playback status (play, pause, etc) accordingly. However, this does not influence how the component looks. So I'm wondering where to perform the update actions?

I was using componentWillReceiveProps to control the playback when the prop is updated, it works but apparently that is incorrect use according to the React team, and the method will be deprecated.

Upvotes: 0

Views: 48

Answers (1)

Ross Sheppard
Ross Sheppard

Reputation: 870

You need to dispatch an action with the selected playback status within the onClick function that is passed through a reducer and updates the state of the store. The component, if connected properly to the store using the connect function in the react-redux library, will automatically update the rendering of the component.

Upvotes: 1

Related Questions