0

I'm trying to change data after fetching them in componentDidMount function.

Let's say I'm fetching one object:

{
  text: "hello world"
}

​but I want to add "!" to this string after fetching in componentDidMount. My question si, where should I edit fetched data? When I'm trying to edit it in componentDidMount I always get error saying that I cannot edit 'undefined'.

Thanks in advance.

1 Answer 1

1

Be a little more specific, its better if you show your fetch function and your modify function also. But, I can guess something similar to it:

 componentDidMount() {
    fetch(reqObj)
      .then(json => {
        const modifyJson = JSON.stringify(json) + '!'
        this.setState({text: modifyJson})
      })
  }
Sign up to request clarification or add additional context in comments.

3 Comments

I guess the OP wants to append ! to hello world, not to the JSON blob. But generally the right idea.
I figured out that the best solution to this problem would be to edit data coming from server in action creator. I didn't think about that. What do you think about that idea?
It is how I do in my project :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.