N
N
Ninja Mate2016-02-17 17:59:54
JavaScript
Ninja Mate, 2016-02-17 17:59:54

Like a setState button on an element that will change the state of the element one level up?

There is such an application

import { UserFirstForm } from './UserFirstForm'; Здесь декларировать передачу стейта?
import { UserHome } from './UserHome'; 
import....

class GridView extends Component {
    constructor(...args) {
        super(...args);
        this.state = {
            form: <UserFirstForm/> или Здесь декларировать передачу стейта?
        };
    }
    render() {
        return (
            <div>
                     {this.state.form}
                     <Button  onClick={() => this.setState({ form: <NewPatient/> })} ></Button>
            </div>
        );
    }
}

export class App extends Component {
    render() {
        return (
            <GridView/>
        );
    }
}

In this case, the button changes the state in its parent element, but I want to do <UserFirstForm/> <UserFirstForm />others, so that they change the state in the parent. How should the declaration of a parameter look like so that the state takes the value children?
export class UserHome extends Component {
    constructor(...args) {
        super(...args);
        this.state = {
             Как задекларировать стейт? :  что то принимает за значение....
        };
    }

    render() {
        return (
            <div>
                <ButtonGroup justified>
                    <Button onClick={????} >Patient<br/>Service</Button>
                    <Button onClick={????} >Non-patient<br/>Service</Button>
                    <Button onClick={????} >Engagement</Button>
                </ButtonGroup>
            </div>
        );
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aves, 2016-02-17
@Aves

Make a method in the parent component and pass it to the child in props.

A
Anton, 2016-02-18
@SPAHI4

I think in this case it makes sense to use a router, and just change the url for each state

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question