ComponentWillMount warning
Asked Answered
M

5

7

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 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.

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

This is the code of the component with

 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>
    );
}
}
Monogram answered 7/3, 2018 at 13:20 Comment(3)
Which version you are using of react?Ample
"react": "^16.3.0-alpha.1", "react-native": "0.54.0",Monogram
Here check this outColiseum
L
5

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

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.

Liston answered 8/3, 2018 at 5:43 Comment(0)
V
0

I think, the ref of componentWillMount is in Component class implementation. not in the extend.

Videlicet answered 7/3, 2018 at 13:23 Comment(0)
F
0

It is because componentWillMount will get deprecated soon in the next major version.Even if you are not using it getting this warning is to prevent you from using as it is the part of lifecycle we commonly use.

Forkey answered 8/3, 2018 at 5:24 Comment(0)
V
0

ComponentWillMount is deprecated in react from version 16. You should move all the code from the componentWillMount to the constructor or componentDidMount.

Please refer to below link for more explanation. https://reactjs.org/docs/react-component.html#componentwillmount

Volsung answered 14/9, 2018 at 14:18 Comment(1)
OP explicitly said they were not calling componentWillMount directly.Esperanzaespial
H
0

componentWillMount could be easily fixed with a constructor initialization or possibly with componentDidMount

it work for me :)

Hauteur answered 13/7, 2020 at 10:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.