React isValidElement comes out as false

前端 未结 1 697
花落未央
花落未央 2021-02-15 22:31

Here is a simple example:

const Foo = () => {
    return (
    
foo
); } class Bar extends React.Component { render() { retur
1条回答
  •  鱼传尺愫
    2021-02-15 23:01

    Component != Element

    Foo and Bar are components. An element is basically the result of "instantiating" (also not really, not sure what the right term is) a component. It's the combination of a constructor/function/string (for HTML components), props and children.

    You get an element when you call React.createElement(Foo), which is what is doing under the hood.

    const Foo = () => {
        return (
        
    foo
    ); } console.log(React.isValidElement()); console.log();
    
    

    0 讨论(0)
提交回复
热议问题