[英]access context in getDerivedStateFromProps in react
我正在使用類來使用 React.createContext
const config = React.createContext()
class MyApp extends Component {
static contextType = TenantConfig
static getDerivedStateFromProps(){
this.context // I can't do this here
}
render(){
return <div>anything</div>
}
}
MyApp.contextType = config
export default MyApp
如何在 getDerivedStateFromProps 中訪問 this.context?
不能在靜態函數中使用this
關鍵字。
您始終可以使用componentDidMount
或componentDidUpdate
進行任何比較。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.