Guest User

Untitled

a guest
Jan 22nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import React, { useState, useEffect } from 'react';
  2.  
  3. export default function MyComponent() {
  4. const [text, setText] = useState();
  5. const updateText = (e) => setText(e.target.value);
  6. const clearText = () => setText('');
  7. const textarea = React.createRef();
  8.  
  9. useEffect(() => textarea.current.focus());
  10.  
  11. return (
  12. <div>
  13. <textarea
  14. value={text}
  15. onChange={updateText}
  16. ref={textarea}
  17. autoFocus>
  18. </textarea>
  19. <button
  20. type="button"
  21. onClick={clearText}
  22. >Clear
  23. </button>
  24. </div>
  25. );
  26. }
Add Comment
Please, Sign In to add comment