Skip to content

React.render is deprecated #432

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

Closed
inchr opened this issue Dec 29, 2015 · 8 comments
Closed

React.render is deprecated #432

inchr opened this issue Dec 29, 2015 · 8 comments

Comments

@inchr
Copy link

inchr commented Dec 29, 2015

When I load a component with react-rails I get this warning:
Warning: React.render is deprecated. Please use ReactDOM.render from require('react-dom') instead.

Why ? I've checked and I'm running react-rails 1.5.0(that in theory is updated to react 0.14.3)

@smnplk
Copy link

smnplk commented Dec 31, 2015

Same issue here.

@SylarRuby
Copy link

Show us some code

@rmosolgo
Copy link
Member

I'm running 1.5.0 without any warnings. I can think of a few things to try:

  • Make sure to restart your development server after installing the new gem. Otherwise, it might serve an old version of the assets.
  • Application code may be using React.render, you should update to ReactDOM.render.
  • You may have a dependency (like a React component you downloaded) which uses React.render. You can search your dependencies and update any of them which use the old API.

If those don't help you, please paste the full stack trace here -- that will show the exact line where the React.render call is coming from. You can see the full trace by expanding the warning (Chrome):

warning

@smnplk
Copy link

smnplk commented Jan 1, 2016

I'm using react-rails in combination with browserify-rails. I scanned the react_ujs code and I see where it is using React.render instead of ReactDom.render, so I just had to add sprockets import //= require react before //= require react_ujs and there is no more warning.

But after //= require react_ujs I am also doing //= require components where I need to require React via node module system:

var React = global.React = window.React = require('react');
var ReactDom = global.ReactDom = window.ReactDom = require('react-dom');

I hope this does not compile two same versions of react library into application.js file and makes react code load twice. Need to check that. Thanks for the tips @rmosolgo

Edit: React is loaded twice if i do this :( My setup is the same as suggested here #413 (comment).

So to sum up, if I add sprockets directive //= require react above //= require react_ujs, react will be loaded twice. If I remove //= require react, all works fine, except that render function is not called on ReactDom object, instead it's called on React. Because it looks like ReactDom is not loaded before react_ujs.js is. https://github.com/reactjs/react-rails/blob/master/lib/assets/javascripts/react_ujs.js.erb#l57

I'm using latest sprockets gem (3.5.2), browserify-rails (1.5.0) and react-rails (1.5.0)

@smnplk
Copy link

smnplk commented Jan 1, 2016

Oh, moron me. I was setting the ReactDom variable instead of ReactDOM 👊 Issue solved :)

@inchr , all you need to do is require ReactDOM.

@inchr
Copy link
Author

inchr commented Jan 7, 2016

Sorry guys, I was offline for holidays...
I've fixed following the @smnplk suggestions, but my code it's like this:

window.ReactDOM = require('react-dom');

(in my main.jsx, that is the entry point of webpack...I load react from webpack too, and I load the react-ujs after the bundle of webpack)

@lokeshjain2008
Copy link

@inchr If all good then close this issue.

@inchr
Copy link
Author

inchr commented Feb 11, 2016

@lokeshjain2008 Oh sorry, my fault! I'm new in github! done!

@inchr inchr closed this as completed Feb 11, 2016
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

5 participants