K
K
Kirr072021-10-10 18:24:13
React
Kirr07, 2021-10-10 18:24:13

How can I make it so that only one paragraph is visible depending on the selection?

Given a select and 3 paragraphs. You can select one of three items in the select. You need to make sure that one of the three paragraphs is visible on the screen, depending on the selection.

state = {
          value: 0,
          options: [ '1', '2', '3' ],
        }
        render() {
          const { value, options } = this.state;
        
          return (
            <div>
              <select>
                {options.map((n, i) => <option value={i}>{n}</option>)}
              </select>
              <br />
              <p style={{opacity: 0}}>1 text</p>
              <p style={{opacity: 0}}>2 text</p>
              <p style={{opacity: 0}}>3 text</p>
            </div>
          );
          }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Chipekwe, 2021-10-10
@XanXanXan

In stateyou need to add a value that will indicate the currently selected element.
Depending on this value, show the desired paragraph.
When changing to selectchange this value to state.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question