数据传输的时候.this上显示是有值的,但是this.props显示是空值。
如何解决API赋值后从一个页面传输到另一个页面
我是这样写的
但是现实的初始值
console.log(123, this) 之所以能够看到是因为console的是 this的引用。
你的流程是
return (<div>{t.state.fetchUrls && <Modal data={t.state.fetchUrls}/>}</div>)
最后推荐你用hooks来写
function Modal(props){
const [details, setDetails] = React.useState(null)
React.useEffect(()=> {
if (!props.data) { return; }
fetchDetails(props.data).then(setDetails)
}, [props.data])
if (!props.data) { return null; }
return <div>{!details ? "Loading": JSON.stringify(details)}</div>
}