Ad

How To Correctly Return A Const With A Button In A TextArea ReactJs

- 1 answer

I would like to explain my problem of the day.

I have 2 const

const a = data.hi?.map((e) =>
    e?.hello?.label.toString()
);


const b = data.hi?.map((e) =>
 e?.bye?.label.toString());

currently, I have 2 buttons

<>
  <Button> A </Button>

  <Button> B </Button>
</>

I also have input text and state

const [text, setText] = useState("");

   <TextArea value={text} />

and so I am looking for when I click on button "A", it returns the value of my const "a" in my TextArea.

I am open to any proposal thank you very much.

thanks, Neff

Ad

Answer

it's simple

<Button onclick={() => {setText(a)}>
   A
 </Button>
Ad
source: stackoverflow.com
Ad