0

There is a field in which the static path of file formation is registered. I have made this field editable in case the user wants to change the path for the formation according to his desire.

<div className="w3-col l8 m8 s8">
    <input
        className="w3-input"
        type="text"
        name="file_name"
        defaultValue={`${test_path}`}
        disabled={false}
    />
</div>

Так же есть кнопка, при клике которой вызывается функция формирования файла по заданному пути

<Btn_enabled
    func={() => create_file(`${test_path}.xmind`)}
    name="Create file"
/>

How can I transfer the modified path by the user to the button?

1 Answer 1

1

You need to introduce a state for your input component.

And just reference it (by passing it through props, state manager, etc).

For example, input value state named value:

// With hooks
function InputValueToButton() {
  const [value, setValue] = useState(testPath);
  return (
    <div className="App">
      <input
        onChange={e => setValue(e.target.value)}
        type="text"
        value={value}
      />
      <Btn_enabled func={() => create_file(`${value}.xmind`)}/>
    </div>
  );
}

If you are using a version of React that does not support hooks, you can achieve the same thing using classes:

// React classes
class InputValueToButton extends React.Component {
  state = {
    value: testPath
  };
  render() {
    return (
      <div className="App">
        <input
          onChange={e => this.setState({ value: e.target.value })}
          type="text"
          value={this.state.value}
        />
        <button>{this.state.value}</button>
      </div>
    );
  }
}

Edit Q-56619864-SO

Sign up to request clarification or add additional context in comments.

1 Comment

This example uses React Hooks, so you'll need to be on a recent version of react

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.