react-native 生命周期

来源:互联网 发布:华为误删移动用户数据 编辑:程序博客网 时间:2024/06/10 04:28

react-native 生命周期

1.创建阶段

1.getDefaultProps() 处理外部传进来的属性,建议使用

    static defaultProps = {        title: '',  // 标题    };

2.实例化阶段

1.render() 启动之后,渲染布局
2.getInitialState() 初始化组件的state值,建议使用

    constructor(props) {        super(props);        // 设置state的值        this.state = {            isOn: false,        };    }

3.componentWillMount() 在render之前调用此方法,如处理state的操作
4.componentDidMount() 在render之后调用
5.componentWillUnmount()组件将要被卸载

componentWillUnmount() {}
原创粉丝点击