当我使用 reactn 库(管理和促进钩子)来获取我用 setGlobal 分配的初始全局状态时,它没有设置任何东西。当我试图得到它说未定义。
我以前使用过这个库,它通常只是导入的问题: import React from "reactn"; 从“reactn”导入 { setGlobal };
然后只需设置全局变量。
import React from "reactn";
import { setGlobal } from "reactn";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
ReactDOM.render(<App />, document.getElementById("root"));
setGlobal({
test: "test",
something: { attr1: "something", attr2: "something", attr3: "something"}
});
serviceWorker.register();
import React, { useEffect, useGlobal } from "reactn";
export default function Engine(props){
const [something, setSomething] = useGlobal("something");
const [test] = useGlobal("test");
console.log(something, test)
useEffect( ()=>{
console.log(something, test)
} );
return(
<div></div>);
}
我期望我应该得到的值而不是 undefined undefined