Skip to content

Instantly share code, notes, and snippets.

@nottyo
Created February 25, 2022 06:59
Show Gist options
  • Select an option

  • Save nottyo/ba93a8ca6cea9e21405372cde513397a to your computer and use it in GitHub Desktop.

Select an option

Save nottyo/ba93a8ca6cea9e21405372cde513397a to your computer and use it in GitHub Desktop.
RTL - Practices - Parent
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