I am making a bio using react but once it is made and the submit is clicked, I want it to transform into just readable text but it does not change the textArea when I click submit.
const [textAreaValue, setTextAreaValue] = useState('');
const changeArea = (event) => {
setTextAreaValue(event.target.value);
console.log(textAreaValue);
}
<div className="bio">
{changeArea.clicked ?
//I want this display with the value
<div className='bioText'>{textAreaValue}</div> :
<textarea placeholder='Enter your bio here' onClick={changeArea}/>}
</div>
Okay I do not understand I put that in and it gives me undefined for changeArea.clicked and a function for changeArea i get the whole string when I submit but how do I make an if statement with submit?
<div className="bio">
{console.log({changeArea, 'changeArea.clicked': changeArea.clicked})}
//when clicked gives the string value
<div className='bioText'>{textAreaValue}</div>
<textarea placeholder='Enter your bio here' onChange={changeArea}/>
</div>
<button onClick={changeArea} className='subBio'>Submit</button>
I have a method changeArea that collects input and then when submit is pressed will set textAreaValue to what is in the box but what I don’t understand is how to write a if statement that shows
when the submit button is clicked shows the value of that string entered but if it is not shows the text area.
Is it going to be a form submission or just a button click?
I would make the textarea a controlled input, and change the event to onChange for it. Then create a boolean state variable to toggle between the two layouts on the button click.