briefy / notes

notes to problems encountered
1 stars 0 forks source link

Heads-up in reactjs #7

Open briefy opened 7 years ago

briefy commented 7 years ago

react

<TabPane name="li" children={<div></div>}>
   {
     [1,2,3].map(index=>{
       return 1
     })
   }
</TabPane>
briefy commented 7 years ago

in react, children prop can be a node or can be an array or even an iterator which yields node type object;

//  the input JSX
const eles = [1,2,3];
<div>
  <div></div>
  {[1,2,3]}
  {eles.map(data=>{
    return (<li>data</li>)
  })}
</div>
// -----------------------------
// the output createElement js
var eles = [1, 2, 3];
React.createElement(
  "div",
  null,
  React.createElement("div", null),
  [1, 2, 3],
  eles.map(function (data) {
    return React.createElement(
      "li",
      null,
      "data"
    );
  })
);
briefy commented 7 years ago

react element

(<Foo></Foo>).type let ele = <Foo></Foo>; ele.type

  var element = {
    // This tag allow us to uniquely identify this as a React Element
    $$typeof: REACT_ELEMENT_TYPE,

    // Built-in properties that belong on the element
    type: type,
    key: key,
    ref: ref,
    props: props,

    // Record the component responsible for creating this element.
    _owner: owner,
  };
briefy commented 7 years ago

in react, here are some types that you should know: NODE : null undefined string number array iterator yields node type react-element(Dom-element || component-element) ELEMENT dom-element component-element

So, React.createElement & React.cloneElement refers to ELEMENT