Created
June 26, 2020 15:45
-
-
Save argodeep/f23618afa530b12e0c6a313e72f3c2d0 to your computer and use it in GitHub Desktop.
React Controlled Component
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
| function handleInput(input: string) { | |
| setKeyword(input) | |
| if (input) { | |
| props.onChange(input); | |
| } else { | |
| props.onChange('') | |
| } | |
| } | |
| <Fragment> | |
| <input type="text" style={{ padding: '1px 2px', height: 'fit-content' }} value={keyword} onChange={(event) => handleInput(event.target.value.trim().toLowerCase())} placeholder={props.text} /> | |
| <span className="clear" onClick={() => { | |
| props.onChange(''); | |
| setKeyword(''); | |
| dispatch(isSorted(false)); | |
| }}>Clear</span> | |
| </Fragment> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment