0

I'm trying to pass Devise data to a React component. Devise is set up correctly, but I can't figure out how to pass the current_user info as props to my react_component. the React props current_user keeps logging as non-existent. I'm using React v5.1 and React-Rails v2.4.

index.html.erb

<%= react_component 'Main', props: {current_user: @current_user} %>

_main.js.jsx

var Main = createReactClass({
    render () {
        return (
            <div>
                {this.props.current_user.id}
                <Header />
                <Body />
            </div>
        );
    }
});
Aidan Low
  • 27
  • 1
  • 8

2 Answers2

0

Try props: {current_user: current_user} instead of props: {current_user: @current_user}

Marty
  • 534
  • 8
  • 24
0

It should be like the following

<%= react_component 'Main', props: {current_user: current_user.to_json} %>

React side

var Main = createReactClass({
    getInitialState() {
    return {
      currentUser: this.props.current_user
    };
    render () {
        return (
            <div>
                {this.state.currentUser.id}
                <Header />
                <Body />
            </div>
        );
    }
});