Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access railsContext in components #763

Closed
othierry opened this issue Mar 18, 2017 · 1 comment
Closed

Cannot access railsContext in components #763

othierry opened this issue Mar 18, 2017 · 1 comment

Comments

@othierry
Copy link

Congratulation for the great work on react_on_rails! 👍

I have just started trying it out. I am facing an issue where I cannot access the railsContext in the constructors of my components. It is always an empty Object {}.

Tracking down the stack brings me to node_package/src/createReactElement.js, because my component is a react component and not a generator function that returns one, it uses React.createElement(component, props) thus, discarding the railsContext.

export default class NavigationBar extends React.Component {

  constructor(props, _railsContext) {
    super(props)

    console.log(_railsContext) // Object {}
  }
  ...
}
import ReactOnRails from 'react-on-rails'
import NavigationBar from '../containers/navigation-bar'

ReactOnRails.register({
  NavigationBar
})
  <body>
    <%= react_component 'NavigationBar' %>
    ...
  </body>

What am I doing wrong ?

@justin808
Copy link
Member

Hi @othierry, the docs specify your answer. You need to use a generator function.

https://github.com/shakacode/react_on_rails/blob/master/README.md#rails-context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants