当我获得新动作时,我需要使用新道具重新渲染子元素。
这是我的应用程序:
export const App: FC = memo(() => {
const [appState, dispatch] = useReducer(reducer, { notes: [], id: -1 });
const assistantStateRef = useRef<AssistantAppState>();
const assistantRef = useRef<ReturnType<typeof createAssistant>>();
const ChangePage = async (page: string) => {
history.push(page);
}
const history = createBrowserHistory();
var appeal = ""
var vuid = ""
const forceUpdate = useReducer(() => ({}), {})[1] as () => void
useEffect(() => {
assistantRef.current = initializeAssistant(() => assistantStateRef.current);
assistantRef.current.on("data", ({ action }: any) => {
if (action) {
console.log(action)
switch (action.type) {
case "init-user":
appeal = action["character"]["appeal"]
vuid = action.user_id;
forceUpdate()
break
}})
return (
<Router history={history}>
<Switch>
<Route exact path="/" render={(props) => <PMain userID={vuid} appealR={appeal} {...props} /> } >
</Route>
</Switch>
</Router>
);
如何在收到类型为 PMain
的操作后使用新的 props 更新 init-user
?