H
H
Hlib2019-05-18 22:50:54
HTML
Hlib, 2019-05-18 22:50:54

How to change text in html using react?

Let's imagine we have some house element
For example:

<ul>
<li>Hello</li>
</ul>

How to change value in li using React js?
PS I myself understand that stupidly an easy question, but the brains just got up

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kova1ev, 2019-05-19
@kova1ev

if the component is defined via a function:

import React, { useState} from "react";

function App() {
  const [value, setValue] = useState("Hello");

  const handleClick = (e) => {
    setValue(prompt("введите значение", value))
  }

  return (
    <div className="App">
      <ul>
        <li onClick={handleClick}>{value}</li>
      </ul>  
    </div>
  );
}

if via class then use State and setState to change.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question