react : Textarea.js:16 Uncaught TypeError: Cannot read properties of undefined (reading 'toUpperCase') at onUpClick (Textarea.js:16:1)

Viewed 54

i was trying to make a textbox that converts the text into upper case and i am facing errors in the console like this: "Textarea.js:16 Uncaught TypeError: Cannot read properties of undefined (reading 'toUpperCase') at onUpClick (Textarea.js:16:1)" can someone please tell me wheere did i go wrong!

please help me out guys

1 Answers

Change onClick in your button to <button onClick={e => onUpClick()} ... becouse <button onClick={onUpClick} ..> triggers once the component mount and then it will call toUpperCase() where the text is undefined Or you could just in your useState do this useState("") set an initial value to it insted of undefined

Related