<Placemark
options={{
iconLayout: 'default#image',
iconImageHref: 'здесь путь к вашей картинке',
}}
/>
const App = () => {
const [showComponent, changeShowComponent] = useState(0)
return <div>
<button onClick={() => changeShowComponent(1)}>Начинаем</button>
{showComponent === 1 && <FirstModalComponent changeShowComponent />}
{showComponent === 2 && <SecondModalComponent changeShowComponent />}
</div>
}
changeShowComponent(2)
и все перерисуется, первый компонент исчезнет, второй появится date.add(1, 'month').clone()
function App() {
const [ items, setItems ] = useState([]);
const onItemClick = ({ target: { dataset: { id } } }) =>
setItems(items.filter(n => n !== +id));
const onAddNewClick = () =>
setItems([ ...items, 1 + Math.max(0, ...items) ]);
return (
<div>
{items.map(n => <button onClick={onItemClick} data-id={n}>#{n}</button>)}
<button onClick={onAddNewClick}>add</button>
</div>
);
}
You may call setState() immediately in componentDidMount(). It will trigger an extra rendering, but it will happen before the browser updates the screen. This guarantees that even though the render() will be called twice in this case, the user won’t see the intermediate state.
я же не могу писать для каждого запроса
let [weatherData, setWeatherData] = useState({})
let fetchWeatherData = async() => {
let url = `https://api.openweathermap.org/data/2.5/forecast?q=Chicago&APPID=${process.env.APIKey}&cnt=5`
let response = await fetch(url);
let data = await response.json()
await setWeatherData(data)
}
useEffect(()=>{
fetchWeatherData()
}, [])