C
C
copal2015-12-04 18:05:24
JavaScript
copal, 2015-12-04 18:05:24

How to assign a react component to a link?

This is how it doesn't work -

store_changeHandler = (event)=>{
    var Component = this.props.store.view;
    this.setState({
        component: <Component />
    });
};

render() {
    return <div>{this.state.component}</div>;
}

And this is how it works -
store_changeHandler = (event)=>{
    this.setState({
        component: this.props.store.view
    });
};

render() {
    var Component = this.state.component;
    return <div>{<Component />}</div>;
}

Question - how to make the first option work? And why doesn't it work in the first case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Prozorov, 2015-12-06
@copal

This is how it will work:

store_changeHandler (event) {
    var Component = this.props.store.view;
    this.setState({
        component: (<Component />) 
    });
};

render() {
    return <div>{this.state.component}</div>;
}

Full example here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question