I
I
Ildar Gizetdinov2017-03-27 00:11:24
React
Ildar Gizetdinov, 2017-03-27 00:11:24

How to render a finished class?

there is a class:

class ExtraClassName extends React.Component {
    render() {
        return <div />;
    }
}

Next, I initialize it: And I try to render it accordingly:
var ecn = new ExtraClassName ({});
render() {
  return (
    <div>{ecn}</div>
  );
}

In response I get:
Objects are not valid as a React child (found: object with keys {props, context, refs, updater, state})
What am I missing? I declare in advance in order to save a link to it, for further
UPDATE operations:
in the bins (quite somewhere far away) I found what I need to write {enc.render()}
But then another question arises, how can I pass the key to him in this case? React issues a warning for this

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Shvedov, 2017-03-27
@mmmaaak

In react, rendering a component is done like this:

render() {
  return (
    <div>
        <ExtraClassName key={somedata} />
    </div>
  );
}

no need to create its instance by hand

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question