Hi I am struggling to get my head around how I return some data from a child to a parent?
I am trying to create components to organise my code.
I have an area that I have extracted that deals with the user selecting if they want to Gift Aid on a donation.
import React, { useState } from 'react';
type Donation = {
donation: number;
};
export default function GiftAid({ donation }: Donation) {
const [giftAid, setGiftAid] = useState(false);
return (
<section>
<div className="mt-12 flex items-center flex-col text-center">
<img src="/images/gift-aid-logo.png" alt="Gift Aid" />
<h2 className="mt-8 text-4xl font-semibold text-gray-800">
Are you a UK tax payer?
</h2>
<p className="mt-4 text-gray-700">
Gift Aid is reclaimed by the charity from the tax you pay for the
current year. Your address is needed to identify you as a current UK
taxpayer.
</p>
<p>
Boost your donation by
<strong className="text-gray-800 font-semibold text-lg">
25%
{donation > 0 && (
<span>
(
{new Intl.NumberFormat('en-GB', {
style: 'currency',
currency: 'GBP',
}).format(donation * 0.25)}
)
</span>
)}
</strong>
at no extra cost to you.
</p>
<label className="flex flex-col items-center mt-4">
<input
type="checkbox"
className="h-6 w-6 border-2 rounded text-blue-800"
onClick={() => setGiftAid(!giftAid)}
/>
<span className="mt-4 text-md font-semibold">
Please claim Gift Aid on my behalf
</span>
</label>
</div>
{giftAid && (
<div className="mt-4 text-gray-400 text-center">
<p>
I confirm that this is my own money and I would like The Gerry
Richardson Trust to treat all the donations I have made in the past
4 years (if any) and any future donations I make, unless I notify
you otherwise, as Gift Aid donations.
</p>
<p className="mt-2">
I also confirm that I am a UK taxpayer and understand that if I pay
less Income Tax and/or Capital Gains Tax in the current tax year
than the amount of Gift Aid claimed on all my donations it is my
responsibility to pay any difference.
</p>
</div>
)}
</section>
);
}
I am passing the amount of the donation down to the component and it renders the correct calculation advising the user of how much they can add to their contribution. I use this component like this:
<GiftAid donation={donation} />
What I need to know now is if this is true or false.
I have an API that I pass the boolean to so I need to pass the giftAid state back up into the parent component? I just cant seem to figure this out? Any pointers, sites or videos to watch?
Thanks in advance