javascriptreactjsbuttoninputstate

how to correctly return a const with a button in a TextArea ReactJs


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.


Solution

  • it's simple

    <Button onclick={() => {setText(a)}>
       A
     </Button>