javascript - React add new props to cloned element with spread operator -


i have container so:

const reactcontainer = ({ children, ...rest }) => react.cloneelement(children, rest); 

now, want add new props - count , flag - cloned elements:

so tried this:

const reactcontainer = ({ children, ...rest }) => {     const count = 0;     const flag = false;      return react.cloneelement(children, {count, flag}, rest); }; 

but doesn't work , i've tried other variations. how can add these new props cloned elements keeping spread operator simplicity?

please try this:

const reactcontainer = ({ children, ...rest }) => {     const count = 0;     const flag = false;      return react.cloneelement(children, {...rest, count, flag}); }; 

please note in above example ...rest used in component function definition acts rest parameters syntax while in cloneelement acts spread syntax.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -