Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

react complains props is not a plain object #14

Open
nippur72 opened this issue Jul 27, 2016 · 1 comment
Open

react complains props is not a plain object #14

nippur72 opened this issue Jul 27, 2016 · 1 comment

Comments

@nippur72
Copy link

I have the following react code running in node.js:

let fn = _eval(
`
      var React = require("react");
      module.exports = function(props,el) {
         return React.createElement("div",{},"hello");
      }
`
, "eval", {}, true);
let component = React.createElement(fn, { name: "John" });           
let s = ReactDOMServer.renderToString(component);
console.log(s);

but react complains that

Warning: React.createElement(...): Expected props argument to be a plain object. Properties defined in its prototype chain will be ignored.

Does anybody knows why this is happening and is there something I can do?

Of course there is no warning if I execute outside of _eval. I should mention also that the above warning was introduced with facebook/react#6134

@philiptzou
Copy link

philiptzou commented Aug 27, 2016

I encountered the same problem when I trying to evaluate a piece of string which contains calls to React.createElement. And I found the reason is that node-eval used vm which created an entirely new context:

const evaluate = require('eval');

const O2 = evaluate("module.exports = Object;");
console.log(O2 === Object); // output false

The solution is to prevent usage of vm or just use vm.runInThisContext. Additionally, I found another package named require-from-string doesn't have the problem since it used a different approach to load values from strings.

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

No branches or pull requests

2 participants