N
N
Ninja Mate2016-02-16 19:28:47
JavaScript
Ninja Mate, 2016-02-16 19:28:47

How to render a ReactJS component?

There are three components App.js First.js and Second.js
In App I declare and render how now when I press the button in First, replace it with <Second/>?
Or is it not possible for an element to replace itself?
Is it possible to set State as an element in App and if possible, then an example if there is one?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Ninja Mate, 2016-02-16
@victorzadorozhnyy

So far, I got out of the situation in this way, but part of the question
Or is it impossible for an element to replace itself? still relevant

constructor(...args) {
        super(...args);
        this.state = {
            form: <First/>
        };
    }


{this.state.form}


 <Button  onClick={() => this.setState({ form: <Second/> })} >Create a new Patient</Button>

A
Anton Izmailov, 2016-02-17
@WapGeaR

Because the editor is just a View representation of the MVC model (as the description says, although for me react is more suitable for SAM), then for such purposes you need to use Flux / Redux / ... other :)
And from there choose the behavior model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question