Javascript 如何重新提交不同的功能组件?
我正在尝试解决如何重新加载不同的功能组件Javascript 如何重新提交不同的功能组件?,javascript,reactjs,micro-frontend,Javascript,Reactjs,Micro Frontend,我正在尝试解决如何重新加载不同的功能组件 onComplete: function (data) { console.log("everything is complete"); console.log("this is the applicant id", id); let obj; axios .post("http://loca
onComplete: function (data) {
console.log("everything is complete");
console.log("this is the applicant id", id);
let obj;
axios
.post("http://localhost:5000/post_id", {
applicant_id: id,
})
.then((response) => {
obj = response.data.data.data.json_data.result;
});
setTimeout(() => {
if (obj === "clear") {
onfidoOut.tearDown(); // <- the Onfido view did not unmount
renderResult(); // <- BAD APPROACH? `renderResult` renders a HTML node instead of triggers a view rerender.
}
}, 3000);
},
似乎可以使用obj
(来自响应
)来管理状态,例如:
const [receivedResults, setReceivedResults] = useState(false);
然后,当收到响应时:
setReceivedResults(obj === "clear");
并使用该标志允许组件呈现自身(不确定确切语法):
if(接收结果){
返回;
}否则{
返回null;
}
如果需要在两个React组件之间通信或“进入”React组件,使用将非常有效。我得到的receivedResult
未定义。我正在运行if
conditional insidesetTimeout
。if
将替换出现在
语句中的初始渲染。我正在成功拆除onfido sdk UI,但它不会重定向我。因此,它会在URL中重定向,但不会呈现该组件。
const [receivedResults, setReceivedResults] = useState(false);
setReceivedResults(obj === "clear");
if (receivedResults) {
return <Redirect to="/result" />;
} else {
return null;
}