Javascript – Get kids and props worth in React


In reaction, children it is always one support, Please refer:

function App(props) {
  console.log(Object.keys(props)); // Veja que `children` é uma prop.

  return 
{props.children}
; } ReactDOM.render(

Olá, mundo!

, document.querySelector('#app') );



So if you want to access the entire object prop, you should stop restructuring:

function ElementPai(props){
  console.log(props.children);
  console.log(props); // <-- Agora você tem as _props_. Sempre teve, aliás. :)
}

You can still use unstructuring to access some props like you did with that support children, Please refer:

function ElementPai({ children, someOtherProp, andAnotherProp }){
  console.log(children);
  console.log(someOtherProp);
  console.log(andAnotherProp);
}

Remember that children It is a support, 🙂


Read this documentation to learn more about the restructuring.