-
npm install
-
npm run dev
আমি যখন Edit button এ
click
করলাম, তখন parent component
থেকে আসা onEdit()
ফাংশনটি
props
হিসেবেchild component
এ আসে এবং child component থেকে এই ফাংশনে একটি আর্গুমেন্ট
হিসেবে data
পাঠাই।
ja parent component
e editHandleClick(data)
function e ace ebong parent component tar sathe ei data dite update kore
- onClick={()=>onEdit(task)} [here ,
onEdit
=props,(task)
= data]
-
parent component
থেকে একটাfunction
child component
eprops
হিসেবে পাঠাব।
-
- সেই
ফাংশনটি
বাটনেরonClick
এ কল করতে হবে।child
er vitore
- সেই
-
- ফাংশনের
onClick
jokhonকল
হলে সেই মুহূর্তেডাটা পাঠাবো।
onClick={()=>callParentFunction(data)}
- ফাংশনের
-
- এই ডাটার vittite
প্যারেন্ট কম্পোনেন্টের স্টেট আপডেট
করবো।
- এই ডাটার vittite
Define the function in the parent component:[parentFunction]
import React, { useState } from 'react';
const ParentComponent = () => {
const parentFunction = () => {
console.log('Function in parent component called');
};
return (
<ChildComponent callParentFunction={parentFunction} />
);
};
Pass the function as a prop to the child component::[{ callParentFunction }]
const ChildComponent = ({ callParentFunction }) => {
return (
<button onClick={callParentFunction}>
Call Parent Function
</button>
);
};
Call the function in the child component:
const ChildComponent = ({ callParentFunction }) => {
return (
<button onClick={callParentFunction}>
Call Parent Function
</button>
);
};
import React from 'react';
const ParentComponent = () => {
const parentFunction = () => {
console.log('Function in parent component called');
};
const parentObject = {
key1: 'value1',
key2: 'value2',
};
return (
<ChildComponent
callParentFunction={parentFunction}
parentObject={parentObject}
/>
);
};
const ChildComponent = ({ callParentFunction, parentObject }) => {
return (
<div>
<button onClick={callParentFunction}>
Call Parent Function
</button>
<p>Parent Object: {JSON.stringify(parentObject)}</p>
</div>
);
};
export default ParentComponent;