Child to Parent | React

Solidity Programming Language
2 min readFeb 22, 2022

--

We have 3 pages from top to bottom:

-App

-NewExpense

-ExpenseForm

We try to sent props from ExpenseForm to App.

ExpenseForm

const submitHandler = (event) => { event.preventDefault();

const expenseData =

{

title: enteredTitle,

amount: enteredAmount,

date: new Date(enteredDate),

};

props.onSaveExpenseData(expenseData);

};

Source

We take inputs from user and we get all datas in expenseData

We sent expenseData with onSaveExpenseData adding props tag.

Where to sent ? To the NewExpense !

NewExpense

Really we sent the onSaveExpenseData props from here and ExpenseForm fills this props with expenseData and it sents to NewExpense

return (

<ExpenseForm onSaveExpenseData={saveExpenseDataHandler} />

);

Illustration time

const saveExpenseDataHandler = (enteredExpenseData) => {

const expenseData = {

enteredExpenseData,

id: Math.random().toString()

};

props.onAddExpense(expenseData);

};

Source

NewExpense takes this datas as the parameter in saveExpenseDataHandler function and creates expenseData and it sents with onExpenseData adding props tag.

App

Really we sent onAddExpense props from here and NewExpense fills this props with expenseData and it sents to App.

return (

<NewExpense onAddExpense={addExpenseHandler} />

);

const addExpenseHandler = expense => {

console.log(expense);

}

Source

App page takes this data as parameter (expense) in addExpenseHandler function.

--

--

Solidity Programming Language
Solidity Programming Language

Written by Solidity Programming Language

Solidity basics for beginners: Learn the fundamentals of smart contract development and build your first DApp! #Solidity #Foundry #Ethereum #Opcodes #DApps

No responses yet