A
A
Anton Izmailov2016-03-02 19:37:52
React
Anton Izmailov, 2016-03-02 19:37:52

How to call a component on event'y in react?

There is a Notification component that outputs something like:

render() {
return (<div>{this.props.text}</div>);
}

I need to call it on click or some event, but the call:
select={(id) => (action) => {
                console.log('bla');
                {<Notification text="test" />}
              }}

Doesn't work, console.log is processed, but Notification is not called. How to proceed in this case and how best to implement the notification component?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vsuhachev, 2016-03-03
@vsuhachev

In the state of your application, you have a "notification" field. Display the Notification component when this field is filled in the model. Filling in the field causes the components to be redrawn and the Notification is displayed. On a timer, clear this field so that the notification disappears.
Just keep in mind that react is just a library for rendering components. How to store the state of your application, how to notify react about state changes is a separate topic, in react it is customary to use the flux pattern for this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question