1

I have header with logo. When user logs, another div appears in the header with users name and logout link (changes the state of the app) and content changes. So I would like to pass the state signedup: 1 to react-router so that when user is logged in and goes to /documentation that it shows additional div with his name and logout. And if the user isnt logged in and goes to /documentation that it doesnt show that div.

I have searched on SO and found this Link

var Dashboard = require('./Dashboard');
var Comments = require('./Comments');

var CommentsWrapper = React.createClass({
  render: function () {
    return (
        <Comments myprop="myvalue" />
    );
  }
});

var Index = React.createClass({
  render: function () {
    return (
        <div>
            <header>Some header</header>
            <RouteHandler />
        </div>
     );
  }
});

var routes = (
  <Route path="/" handler={Index}>
    <Route path="comments" handler={CommentsWrapper}/>
    <DefaultRoute handler={Dashboard}/>
    </Route>
);

ReactRouter.run(routes, function (Handler) {
  React.render(<Handler/>, document.body);
});

This works but isnt for my case. As this will not pass changed state only initial. So how would i do this?

I had got an idea to change the content based on state, But the problem with that is back button doesnt work and user cant write /documentation to go to that page.

Community
  • 1
  • 1
MePo
  • 1,044
  • 2
  • 23
  • 48
  • Do you have a store? Redux? – David Gilbertson Jul 29 '16 at 07:18
  • @DavidGilbertson No i dont, i am passing states since i dont have that many pages. Login which passes state to Main page)and registration which was done with react-route as i dont need that additional div there.So i tought that would be enough and i wont need dispatcher, but then i stumbled upon this problem. – MePo Jul 29 '16 at 07:24
  • Fair enough. I think as soon as you get to the point where you're wondering how to share some information between two components (e.g. sign in status), it's time to get a store. Do you know redux? It doesn't need to be very complex. – David Gilbertson Jul 29 '16 at 07:31
  • No i don't. This is my first app in react but now its a good time to learn. When i figure it out ill write it here as an answer. Thanks for pointing that out, now i will know in the future when to use store – MePo Jul 29 '16 at 07:36
  • Have fun! I highly recommend putting aside an hour and watching [these vids](https://egghead.io/courses/getting-started-with-redux) from the maker before getting started. – David Gilbertson Jul 29 '16 at 07:42
  • Thank you for the link this will help me a lot. I will – MePo Jul 29 '16 at 07:44

0 Answers0