Home > Enterprise >  how to correctly return a const with a button in a TextArea ReactJs
how to correctly return a const with a button in a TextArea ReactJs

Time:08-11

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

CodePudding user response:

it's simple

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