ComponentWillMount 警告 [英] ComponentWillMount warning

查看:37
本文介绍了ComponentWillMount 警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个内部布局.我是从另一个场景来到这个场景的.所以在开始时呈现另一个布局.在我进入第二个场景(带有 TextInput 标签)后,我收到如下警告:

I am creating a layout with inside. I am getting to this scene from another. So at the beginning another layout is rendered. After i go to the second scene (with TextInput tag) i obtain warnings such as:

componentWillMount 已弃用,将在下一个版本中移除主要版本.请改用 componentDidMount.作为临时解决方法,您可以重命名为 UNSAFE_componentWillMount.请更新以下组件:应用程序、容器、图像、文本

componentWillMount is deprecated and will be removed in the next major version. Use componentDidMount instead. As a temporary workaround, you can rename to UNSAFE_componentWillMount. Please update the following components: App, Container, Image, Text< TouchableOpacity, Transitioner, View.

这很奇怪,因为我没有使用componentWillMount方法,所以我猜它是隐式调用的.

This is very strange, because I am not using componentWillMount method, so i guess that it is implicitly called.

这是带有

 class MainTopBarAfterSearch extends Component {
constructor() {
    super();
    this.state = { text: " " };
}

render() {
    const { topBarContainer, imageStyle, textInputStyle } = styles;
    return (
        <View style={topBarContainer}>
            <TouchableOpacity onPress={() => Actions.menu()}>
                <Image
                    source={require("../../../resources/menuWhite.png")}
                />
            </TouchableOpacity>
            <TextInput
                style={textInputStyle}
                placeholder="Begin to search"
                value={this.state.text}
                onChangeText={text => this.setState({ text })}
            />
            <Image source={require("../../../resources/filter.png")} />
        </View>
    );
}
}

推荐答案

是的,因为 componentWillMountcomponentWillReceiveProps 在 React 中很快就会被弃用.我建议你使用 componentDidMount 而不是 componentWillMount.

Yes, because the componentWillMount and componentWillReceiveProps getting deprecated soon in React. I suggest you to use componentDidMount instead of componentWillMount.

但是您仍然会收到那些黄框警告,因为 react-native 仍在将它们用于内部组件,例如 ImageTouchableOpacity 和许多其他组件.我们需要等待新的更新来消除这些警告.别担心,快乐编码.

But you will still get those yellow box warnings because react-native is still using those for the internal components like Image, TouchableOpacity and a lot of other components. We need to wait for a new update to get rid of those warnings. Don't worry, Happy coding.

这篇关于ComponentWillMount 警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆