0

There is a html page contains the following html and include a js file

html:

<input type="text" name="customValue" id="customValue" value="">

js file:

    class Calc extends React.Component {
      constructor() {
        super();
      }

      render() {
        return (99)
      }   
    }
    ReactDOM.render(<Calc />, document.getElementById("customValue"));

So my question is how to set the customValue to 99 using reactjs?

1 Answer 1

3

You can do it like this:-

HTML

<div id="rootDiv"></div>

JS

class Calc extends React.Component {
      constructor() {
        super();
      }

      getValue = () => {
          return 99;
      }

      render() {
        const value = this.getValue();

        return (
            <input type="text" name="customValue" id="customValue" value={value}>
        )
      }   
}

ReactDOM.render(<Calc />, document.getElementById("rootDiv"));
Sign up to request clarification or add additional context in comments.

1 Comment

If this answers your question, please accept it so that it helps other people as well. Thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.