Hi All, how do I setState before rendering a compo...
# prisma-whats-new
e
Hi All, how do I setState before rendering a component? I just finished the howtographql tutorial a few weeks ago. I created states newName and newEmail and the componentWilMount: componentWillMount(){ const userId = localStorage.getItem(GC_USER_ID) console.log('userId') console.log(userId) if (this.props.allUsersQuery && this.props.allUsersQuery.loading) { return console.log("loading") } if (this.props.allUsersQuery && this.props.allUsersQuery.error) { console.log(this.props.allUsersQuery.error) return console.log("error") } const result = this.props.allUsersQuery.allUsers console.log(result) const len = result.length console.log(len) for (var i = 0; i < len; i++) { if(result[i].id===userId) { console.log(result[i]) var user = result[i] } } console.log("found") console.log(user) this.setState({newName: user.name}) this.setState({newEmail: user.email}) console.log("END MOUNT") }