Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

pass props in compound component

//parent

const Parent = ({ children }) => {
  const [checked, setChecked] = useState(false);

  const allChildren = React.Children.map(children, (child) => {
    const clone = React.cloneElement(child, {
      checked,
      setChecked,
    });
    return clone;
  });
  return allChildren;
};

//child
const Child = ({  checked, setChecked }) => {
  return (
    <div onClick={() => setChecked(!checked)} style={{ color: "red" }}>
      child content
    </div>
  );
};

//app
<Parent>
    <Child /> 
</Parent>
Comment

how to pass props to another component


//parent component which send the prop value
const parent=(val)=>{
	return <Children value={val}/>;
}
//child component which recive the prop value
export const Children=(props)=>{
	return props.value;
}
Comment

react pass component as props

function Parent({children}) {
  return (
    <div>
      {children}
    </div>
  );
}

export default function App() {
  const Title = () => {
    return <h2>Hello world</h2>;
  };
  
  return (
    <div>
      <Parent>
        <Title />
      </Parent>
    </div>
  );
}
Comment

pass a react component as a prop from another component

[
 {...,one : ComponentOne},
 {...,two : ComponentTwo}
]
Comment

how do you pass props between components

function Greeting(props){
   return(<div>
    //using p
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to log all messages discord.js 
Javascript :: create a reactjs app with backend and docker 
Javascript :: disable js in chrome dev tools 
Javascript :: sort an array 
Javascript :: console log all array values node 
Javascript :: keyboard close when typing react native 
Javascript :: example of callback function in javascript 
Javascript :: chrome.contextmenus 
Javascript :: Javascript print/output 
Javascript :: moment isbetween 
Javascript :: Adding an item to an array 
Javascript :: object methods 
Javascript :: know when recyclerview is on the last item 
Javascript :: twitter javascript api 
Javascript :: get sessionstorage value in jquery 
Javascript :: Material-ui add circle icon 
Javascript :: pattern printing in javascript 
Javascript :: remove duplicate item from array javascript 
Javascript :: php math 
Javascript :: change one element in array javascript 
Javascript :: Passing Boolean values as Props in react 
Javascript :: images node backend server 
Javascript :: if condition to whether json object has jsonarray or jsonobject 
Javascript :: how to defined an array in js 
Javascript :: Material-ui alarm icon 
Javascript :: #{10000000000000000000000000000000000} js 
Python :: import beautifulsoup 
Python :: install matplotlib 
Python :: python exception with line number 
Python :: get ip from instance id boto3 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =