Created
June 10, 2021 14:43
-
-
Save richleach/eb9ec81a6c674409d3d166ead3456370 to your computer and use it in GitHub Desktop.
REACT TESTING LIBRARY - component used to test against
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 "../Counter/counter.css" | |
function Counter() { | |
const [counterValue, setCounterValue] = useState(0) | |
const [inputValue, setInputValue] = useState(1) | |
const addToCounter = () => { | |
setCounterValue(counterValue + inputValue) | |
} | |
const subtractFromCounter = () => { | |
setCounterValue(counterValue - inputValue) | |
} | |
return ( | |
<div> | |
<h3 data-testid="header">My Counter</h3> | |
<h2 data-testid="counter" | |
className= | |
{`${counterValue >= 100 ? "green" : ""}${counterValue <= -100 ? "red" : ""}`} | |
> | |
{counterValue} | |
</h2> | |
<button data-testid="subtract-btn" onClick={subtractFromCounter}>-</button> | |
<input data-testid="input" type="number" defaultValue={inputValue} className="text-center" onChange={(e) => {setInputValue(parseInt(e.target.value))}} /> | |
<button data-testid="add-btn" onClick={addToCounter}>+</button> | |
</div> | |
) | |
} | |
export default Counter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment