0

How can I have a user set a function variable with an input number? I have a form they can enter a number into, but this needs to set the col var up top.

function DataFrame(){

  var element = <li class="element"/>

  var col <- the variable to be set by the form

  var arr = []
  var i
  for (i = 0; i<row; i++){
    arr.push(element)
  }

  const [toggle, setToggle] = React.useState(false);

  const Element = () => <li className="element" />;

  return (

    <div>
      <div >
        <form>
          <label>
          input code:
            <input type="number" name="dimension" />
          </label>
            <input type="submit" value="Submit" />
        </form>
      <div >
    </div>

)

1 Answer 1

2

You may store it within local component's state (setting its initial value to some default one, e.g. 0):

const [col, setCol] = useState(0)

Then, upon input keyUp event, you may modify col by calling setCol with appropriate parameter:

<input type="number" name="dimension" onKeyUp={e => setCol(e.target.value)} />
Sign up to request clarification or add additional context in comments.

2 Comments

what do you mean by "appropriate parameter'?
@VP9 : In your particular case - input value

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.