小编Joh*_*son的帖子

ComponentWillMount 警告

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

componentWillMount 已弃用,将在下一个主要版本中删除。请改用 componentDidMount。作为临时解决方法,您可以重命名为 UNSAFE_componentWillMount。请更新以下组件:App、Container、Image、Text< TouchableOpacity、Transitioner、View。

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

这是组件的代码

 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>
    );
}
}
Run Code Online (Sandbox Code Playgroud)

reactjs react-native react-native-router-flux

7
推荐指数
2
解决办法
7815
查看次数