suppose the state in redux looks like this:
state = {
value:"aaa",
list:["123","321","12231"]
}
The A component is an input,input whose value corresponds to the value in state.
B component is a list,list content that needs to be obtained based on the value value request API, such as http://api.com?query=aaa
as shown in the figure:
when the value of An is updated, the list is retrieved and component B is rendered. The normal logic is as follows:
change event sends an asynchronous action request for a new list = > Update list in redux state = > component B rendering
now is that you cannot add code to the A component change event for some special reason. Can you listen for value changes and update list? from the row in component B?
if you get and update list, in componentWillMount
, it will only be executed once when the B component is initialized, but not again when the value changes.
if you add a method to get and update list in componentWillReceiveProps
, because it is asynchronous, it will result in circular requests and rendering.
ask for help!