[英]How do i call function before page is loaded in react
i'm trying to cal a mutation to verify some information in the backend before the page is loaded in react is there any way I can trigger the function when the page is about to load or is loading我正在尝试调用一个突变以在页面加载之前验证后端中的某些信息以响应是否有任何方法可以在页面即将加载或正在加载时触发 function
You can can have a isLoading state set to true by default.您可以将 isLoading state 默认设置为 true。 Make necessary calls in the useEffect hook and after the calls setIsLoading to false.
在 useEffect 挂钩中进行必要的调用,并在调用后将 setIsLoading 设置为 false。 In the UI part you can do conditional rendering ie if isLoading true do not display anything, else display the UI
在 UI 部分,您可以进行条件渲染,即如果 isLoading true 不显示任何内容,否则显示 UI
Check this检查这个
https://reactjs.org/docs/react-component.html https://www.pluralsight.com/guides/how-to-use-componentwillmount https://reactjs.org/docs/react-component.html https://www.pluralsight.com/guides/how-to-use-componentwillmount
import React from 'react';
export default class App extends React.Component {
render() {
return <div>
Content
</div>
componentDidMount() {
// component mounted
}
componentwillMount() {
// component will be mounted
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.