I am working on a React Native project and I have a function that makes a GraphQL query:
getPosts = async () => {
const result = await API.graphql(graphqlOperation(listPosts))
if(this.state.isMounted){
this.setState({ posts: result.data.Posts.items,
isLoading: false, isMounted: false})
}
}
This function is called in the componentDidMount
function. I also have a isMounted
field in the state
that is initialized to false
. At the very top of the componentDidMount
function I have:
this.setState({ isMounted: true })
Regardless, I am still getting a warning about trying to set the state on an component that is unmounted. I should also mention that this Component is called from this.props.navigation.navigate
call.