<select name="nm" id="nam">
<option value="QBC">QBC</option>
<option value="QEF">QEF</option>
<option value="GHI" selected>GHI</option> <!-- этот вариант будет выбран-->
<option value="KLM">KLM</option>
</select>
import React, { useState, useEffect } from 'react'
const LocalStorage = () => {
const date = [
{ symbol: 'RU', label: 'рубль' },
{ symbol: 'USD', label: 'доллар' },
{ symbol: 'EUR', label: 'евро' }
]
const [curr, setCurrencies] = useState(date)
const [currentSymbol, setCurrentSymbol] = useState("EUR") // опция выбранная по умолчанию (если нет данных в localstorage)
// срабатывает один раз при загрузке компонента
useEffect(() => {
if(localStorage.getItem('symbol')) {
const item = localStorage.getItem('symbol')
setCurrentSymbol(item)
}
}, [])
// обработчик - срабатывает при выборе опции списка
const selectHandler = (e) => {
localStorage.setItem('symbol', e.target.value)
setCurrentSymbol(e.target.value)
}
return (
<div>
<select onChange={selectHandler} value={currentSymbol}>
{
curr.map(currencies => (
<option key={currencies.symbol} value={currencies.symbol}>
{currencies.symbol} {currencies.label}
</option>
)
)
}
</select>
</div>
)
}
export default LocalStorage
import React, { Component } from 'react'
class ClassLocal extends Component {
constructor(props){
super(props);
this.state = {
curr: [
{ symbol: "RU", label: "рубль" },
{ symbol: "USD", label: "доллар" },
{ symbol: "EUR", label: "евро" }
],
currentSymbol: "EUR"
}
}
componentDidMount() {
if(localStorage.getItem('symbol')) {
const item = localStorage.getItem('symbol');
this.setState({currentSymbol: item})
}
}
selectHandler = (e) => {
localStorage.setItem('symbol', e.target.value)
this.setState({currentSymbol: e.target.value})
}
render() {
return (
<div>
<select onChange={this.selectHandler} value={this.state.currentSymbol}>
{
this.state.curr.map(currencies => (
<option key={currencies.symbol} value={currencies.symbol}>
{currencies.symbol} {currencies.label}
</option>
)
)
}
</select>
</div>
)
}
}
export default ClassLocal
if(IsMusicListShowing == 0)
<div>
<MusicLineInSiteMusic onClick={UnshowMusicList}></MusicLineInSiteMusic>
<MusicList MusicLinesInMusicList={MusicLinesInMusicList}></MusicList>
</div>
export const store =[
import {store} from './store';
const questinsArray = props.store.map(store=> (
<FientQuest
key={store.quest}
qmumb = {store.qmumb}
quest = {store.quest}
//...
function bindActionCreator(actionCreator, dispatch) {
return function () {
return dispatch(actionCreator.apply(this, arguments));
};
}
function () {
return dispatch(actionCreator.apply(this, arguments));
};