ReactJs: useState making string empty

// App.js

const [currentContent, setCurrentContent] = useState('')

const openNote = (id) => {

    notes.forEach(note => note.id == id && setCurrentContent(note.content))

}

Part of return:

<TextRegion className="center" content={currentContent}/>

I am passing content as a prop via a state seen in the code block above. This seems to work fine.

// TextRegion.js
import React, {useState} from 'react'


const TextRegion = ({ content  }) => {


const [areaText, setAreaText] = useState(content)
    console.log(areaText)



    return (
    <div className="form-div">
        <form className="form">



                <textarea className="content form-control" type="text" value={content}/>
            
            
            

        <button style={{'float': 'right'}} className="btn btn-primary mt-2 mr-2" type='submit'>Save</button>

        </form>

    </div>

    )



}

export default TextRegion;

The issue arises when I attempt to set the content prop to the default state of areaText. Content is of type string, and prints to console just fine. Although, when trying to print areaText, an empty string is returned. This is baffling to me, any explanations? Thanks.

47 thoughts on “ReactJs: useState making string empty”

  1. I have been browsing on-line greater than three hours lately,
    yet I by no means discovered any interesting article
    like yours. It’s lovely price sufficient for me.
    In my view, if all web owners and bloggers made good content as you probably did, the net will likely be a
    lot more helpful than ever before.

    Reply
  2. Hey! Someone in my Myspace group shared this website with us so I came to check it out.
    I’m definitely loving the information. I’m book-marking and will be tweeting
    this to my followers! Terrific blog and wonderful design and style.

    Reply
  3. I’ve been browsing online more than three hours today,
    yet I never found any interesting article like yours.
    It is pretty worth enough for me. In my opinion, if all site owners and bloggers made
    good content as you did, the web will be a lot
    more useful than ever before.

    Reply
  4. I will immediately take hold of your rss feed as I can not in finding
    your e-mail subscription link or newsletter service. Do you have any?
    Kindly let me recognize in order that I may just subscribe.
    Thanks.

    Reply
  5. It’s appropriate time to make some plans for the future and it’s time to be happy.

    I have read this post and if I could I desire to suggest you some interesting things or suggestions.
    Maybe you could write next articles referring to this
    article. I want to read more things about it!

    Reply
  6. Can I just say what a relief to find someone that truly understands what they’re discussing over the internet.
    You definitely realize how to bring a problem to light
    and make it important. A lot more people ought to check this out and understand this side of the story.

    It’s surprising you aren’t more popular since you definitely have the
    gift.

    Reply

Leave a Comment