I'm trying to become a front-end developer, so I'm creating a project with companies info. I tried to find on YouTube and here, but still I couldn't understand.
I want to use on Change to show the result, but How I pass the option value to the variable?
import React, { Component } from "react"; class BusinessCard extends Component { constructor(props) { super(props); this.state = { loading: true, company: null, }; } async componentDidMount() { let companyCod = "MSFT"; // I want receive the option value here let companyUrl = "https://www.alphavantage.co/query?function=OVERVIEW&symbol=" + companyCod + "&apikey=YOUR-API-KEY"; let response = await fetch(companyUrl); let data = await response.json(); this.setState({ company: data, loading: false }); } render() { if (this.state.loading) { return <div>loading</div>; } return ( <div> <select> <option value="MSFT">MSFT</option> <option value="AAPL">AAPL</option> <option value="IBM">IBM</option> </select> <h1>Company: {this.state.company.Name}</h1> <h1>Symbol: {this.state.company.Symbol}</h1> </div> ); } }
https://stackoverflow.com/questions/65402726/react-selection-option-value-change-the-variable-data December 22, 2020 at 11:02AM
没有评论:
发表评论