How to add new props dynamically to a component using a navigator in React Native

In my script, I process the component using a navigator. In this component, I perform some actions, such as saving the record, after which I added a dynamic addition to the existing component. But here the dynamic support is not visible in this component, only the previous details are visible only. How to achieve adding dynamic support to a component using the navigator.

here I provide the code when using the React Native navigator. I call the DisplayCustomSchema component as shown below.

this.props.navigator.push({ id: 'DisplayCustomSchema', name: 'DisplayCustomSchema', org:this.props.org }); 

In the component DisplayCustomSchema componentDidMount I call one ajax post, it returns some data.

 var DisplayCustomSchema = React.createClass({ componentDidMount : function(){ ajaxpost(data){//example only this.props.record=data //here i am try to move response data to props because I am using this data in saveRecord function but in save record props contain name and org only } } render: function(){ <View> <TouchableHighlight style={styles.touchButtonBorder} underlayColor="#ffa456" onPress={saveRecord.bind(this,this.props)}> <Text style={styles.button}>SAVE</Text> </TouchableHighlight> </View> } }) 

here is my question why the data does not move to the details

+5
source share
1 answer

You have two options.

  • Use state
  • Use a framework like redux

    • Since you cannot set the details, you can use this.setState to set the downloaded data

    • If you use redux, you can submit the installation action, which will then modify the repository to include the downloaded details.

Please note that the second option is highly recommended since using the condition is antipater.

+1
source

Source: https://habr.com/ru/post/1235268/


All Articles