React - render certain div based on react-select selectedOption

React - render certain div based on react-select selectedOption

I'm using&nbsp;<a href="https://github.com/JedWatson/react-select" target="_blank">react-select</a>&nbsp;to render two types of "job" options. From the dropdown the user is able to select either of the options. Based on the option selected they should render different divs that contain more input values. The input values are dependent on the&nbsp;selectedOption. I have two class components with render methods that should display the different inputs corresponding to the&nbsp;jobType

I'm using react-select to render two types of "job" options. From the dropdown the user is able to select either of the options. Based on the option selected they should render different divs that contain more input values. The input values are dependent on the selectedOption. I have two class components with render methods that should display the different inputs corresponding to the jobType

class App extends React.Component {
  constructor(props) {
    super(props);

this.state = {
  selectedOption: null
};

this.onChange = this.onChange.bind(this);
this.handleChange = this.handleChange.bind(this);

}

onChange = e => { this.set({ [e.target.name]: e.target.value }); console.log([e.target.value]); };

handleChange = selectedOption => { this.setState({ selectedOption }); console.log("Option selected: ", selectedOption); };

render() { const { selectedOption } = this.state; return ( <div> <fieldset> <legend>Parameters</legend> <label htmlFor="jobType" style={{ display: "block" }}> jobType: </label> <div> <Select value={selectedOption} onChange={this.handleChange} options={options} placeholder="Select a jobType..." isSearchable={options} /> </div> </fieldset> <div> {selectedOption === "Batch" ? ( <BatchParams /> ) : selectedOption === "Streaming" ? ( <StreamingParams /> ) : null} </div> </div> ); } }

So let's say when the Streaming option is selected from the dropdown the following class component should be rendered:

class StreamingParams extends React.Component {
      constructor(props) {
        super(props);

    this.state = {
      maxHits: 1
    };
    this.handleMaxHitsChange = this.handleMaxHitsChange.bind(this);
  }

  handleMaxHitsChange = e =&gt; {
    this.set({ [e.target.name]: e.target.valu });
  };
  render() {
    return (
      &lt;div&gt;
        &lt;label&gt;maxHits:&lt;/label&gt;
        &lt;input
          type="number"
          name="maxHits"
          onChange={this.handleMaxHitsChange}
          placeholder="1"
          min="1"
          step="1"
          required
        /&gt;
      &lt;/div&gt;
    );
  }
}

I can't quite get the additional input boxes to render, not sure if I'm taking the correct approach here. I have included a codesandbox with my issue.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

ReactJS vs Angular vs Vue: Best Javascript Framework For Your Project

ReactJS vs Angular vs Vue: Best Javascript Framework For Your Project. This video covers the key differences between ReactJS, Angular and Vue with respect to the following: Use case, Performance, Data binding, Scripting language, Testing, Community support, Growth curve

What is JavaScript – All You Need To Know About JavaScript

In this article on what is JavaScript, we will learn the basic concepts of JavaScript.

JavaScript Tutorial: if-else Statement in JavaScript

This JavaScript tutorial is a step by step guide on JavaScript If Else Statements. Learn how to use If Else in javascript and also JavaScript If Else Statements. if-else Statement in JavaScript. JavaScript's conditional statements: if; if-else; nested-if; if-else-if. These statements allow you to control the flow of your program's execution based upon conditions known only during run time.