0

В общем при срабатывании onClick{codeText} текст в первой textarea меняется. Как сделать так чтобы текст удалялся из первой textarea и переносился во вторую?

return(
            <div>
                <h1>{text}</h1>
                <div>
                <textarea className="inputBox" placeholder="Input" value={text} onChange={event => setText(event.target.value)}/>
                </div>
                <div>
                <textarea className="inputBox" placeholder="Output"/>
                </div>
                <button onClick={codeText} className="codeButt">
                    Готово
                </button>
            </div>
        )

1 ответ 1

1

Используйте 2 состояния.

function app() {
  const [value, setValue] = useState('')
  const [performedValue, setPerformedValue] = useState('')
    
  const codeText = () => {
    setPerformedValue(value.toUpperCase())
    setValue('')
  }

  return (
    <div>
      <h1>{value}</h1>
      <div>
        <textarea 
          className="inputBox" 
          placeholder="Input" 
          value={value} 
          onChange={event => setValue(event.target.value)}
        />
      </div>
      <div>
        <textarea className="inputBox" placeholder="Output" value={performedValue} />
      </div>
      <button onClick={codeText} className="codeButt">
        Готово
      </button>
    </div>
  )
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.