Skip to content
Advertisement

useState and useHooks in HTML

first of all, I can not use the “create-react-app” command in the current project.

so here I am trying to add my react code into a plain HTML file.

Here are my codes for HTML and js files.

can anyone tell me why my hooks and setState don’t work properly?

Please guide me to solve it.

JavaScript

my like_button.js codes

JavaScript

Advertisement

Answer

Your trying to return from a useEffect, the return from a useEffect is for cleanUp of an effect,.

In fact you don’t even require to use useEffect, you just need to change your render based on your liked state.

Also your example code you showed has JSX syntax, so not sure why your using createElement but I’ve created the example below without it, just in case..

eg.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement