React inline update component

I have my component that successfully executes another component this way:

const List = require('../List.js');

class MyComponent extends React.Component {
    constructor(props) {
        super(props);
        this.registerListner();
    }
    render() {
        console.log("MyComponent render");
        return (
            <List/>
        );
    }
    registerListener() {
        const emitter = new NativeEventEmitter(MyModule);
        emitter.addListener('onListChange',
            (element) => {
                this.setState({ elements: elements });
                console.log("receive elements: ", elements);
            }
        );
    }
}

module.exports = MyComponent;

      

Now, how can I display the list of "passing" new items again?

+3


source to share


1 answer


When the state is updated with setState, the react automatically calls the render () method. So, all you have to do is:

render() {
    const {elements} = this.state;
    return (
        <List
            items={elements}
        />
    );
}

      



If the List component has a different property name for getting the list items, replace the items with that name.

+1


source







All Articles