passing event handler to useEffeect
const App =() => {
const [userText, setUserText] = useState("");
useEffect(() => {
const handleUserKeyPress = event => {
const { key, keyCode } = event;
if (keyCode === 32 || (keyCode >= 65 && keyCode <= 90)) {
setUserText(`${userText}${key}`);
}
};
window.addEventListener("keydown", handleUserKeyPress);
return () => {
window.removeEventListener("keydown", handleUserKeyPress);
};
}, [userText]); // ESLint will yell here, if `userText` is missing
return (
<div>
<h1>Feel free to type!</h1>
<blockquote>{userText}</blockquote>
</div>
);
}
ReactDOM.render(<App />, document.getElementById("root"));
Also in JavaScript:
- jspdf reduce size file
- how to create my own filter in js
- javascript capitalize first letter
- get dirname to last directory node
- NullInjectorError: R3InjectorError(DashboardModule)[DatabaseService -> DatabaseService -> HttpClient
- import zenodo_upload from '@iomeg/zenodo-upload example
- some in javascript
- js date remove am and pm
- fetch composition API in Vue3
- linking a script .js
- mutable array methods in javascript
- how to move an element of an array in javascript
- syntax to call item from array
- check if string contains substring javascript
- what called window.onerror
- discord js get badge user
- how to trim the file name when length more than 10 in angular
- javascript loop object
- js retrieve form data
- google apps script lock service
- input type shows object angularjs
- postmark with nodejs
- flutter intl currency
- react split array into chunks