How to use React functions in CodePen?
我在CodePem中编写了一个React函数来测试React hooks,但它不断报告错误:Uncaught ReferenceError:require未定义。
我在CodePem中编写了一个测试React hook的react函数,但它不断报告错误:未捕获的引用错误:require未定义。
我的代码:
import {useState, useEffect,useRef } from react ;
function Test() {
const [count, setCount] = useState(0);
const prevRef = useRef();
useEffect(() => {
// const ref = useRef();
console.log( ref---- , prevRef.current);
prevRef.current = count;
})
return (
<div>
<div onClick={() => setCount(count+1)}>+1</div>
<div>{`count: ${count}`}</div>
<div>{`precount: ${prevRef.current}`}</div>
</div>
)
}
ReactDOM.render(<Test />, document.getElementById("app"));