M
M
Maxim2015-08-12 11:27:33
JavaScript
Maxim, 2015-08-12 11:27:33

How to implement React.Navigation in a component?

Need to navigate in react. Application in ES6.
The question is how to inject mixins: [ Navigation ] into a react class?
I don't want to go to React.createClass({})c class Main extend React.Components {}
Decided through context.

static contextTypes = {
    router: PropTypes.object.isRequired
  };

and then you can execute this.context.transitionTo('/')
But there is one BUT, a warning is thrown into the console
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2015-08-13
Antonikhin @STJ

Decision.
In the component, get the router instance from the context.

static contextTypes = {
    router: Router.PropTypes.object.isRequired
}

Then, in the component, the router will be available in the component and it can be used like
this
loaders: [
          { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader?stage=0' },
        ]

R
Ruslan Abdullaev, 2015-08-13
@rajdee

Shouldn't it be this.context.router.transitionTo ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question