Created
February 25, 2022 06:59
-
-
Save nottyo/ba93a8ca6cea9e21405372cde513397a to your computer and use it in GitHub Desktop.
RTL - Practices - Parent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from 'react'; | |
| import Child from './Child'; | |
| const Parent = () => { | |
| const [counter, setCounter] = useState(0); | |
| const handleChildClicked = (count: number) => { | |
| setCounter(count); | |
| }; | |
| return ( | |
| <div> | |
| <h1 data-testid="parent-title">This is Parent</h1> | |
| <Child name="Child Component" onIncreaseClick={() => handleChildClicked(counter + 1)} onDecreaseClick={() => handleChildClicked(counter - 1)} /> | |
| <div data-testid="counter">{counter}</div> | |
| </div> | |
| ); | |
| }; | |
| export default Parent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment