React.useEffect(() => {
(async () => {
try {
const themes = await fetch("/arr").then((data) => data.json());
const activeTheme = Math.floor(themes.length / 2);
const activePlace = Math.floor(themes[activeTheme].subtopics.length / 2);
setThemes(themes);
setActiveTheme(activeTheme);
setActivePlace(activePlace);
} finally {
setIsLoad(false);
}
})();
}, []);
npm i create-react-app -g
create-react-app my-app
const start = 11 * 60 * 60;
const end = 18 * 60 * 60;
const step = 30 * 60;
const count = Math.floor((end - start) / step);
const result: string[] = [];
const date = new Date();
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
const format = (date: Date) => date.toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' });
for (let index = 0; index < count; index++) {
const from = new Date(date.getTime() + (start + step * index) * 1000);
const to = new Date(date.getTime() + (start + step * (index + 1)) * 1000);
result.push(`${format(from)} - ${format(to)}`);
}
console.log(result);
/* [ '11:00 - 11:30', '11:30 - 12:00', '12:00 - 12:30', '12:30 - 13:00', '13:00 - 13:30',
'13:30 - 14:00', '14:00 - 14:30', '14:30 - 15:00', '15:00 - 15:30', '15:30 - 16:00',
'16:00 - 16:30', '16:30 - 17:00', '17:00 - 17:30', '17:30 - 18:00' ] */
const handleIndicatorChangeOne = (event) => {
setValue(values => [Number(event.target.value) || '', values[1]]);
};
const handleIndicatorChangeTwo = (event) => {
setValue(values => [values[0], Number(event.target.value) || '']);
};
onChange
у TextField
необходимо поменять на handleIndicatorChangeOne
и handleIndicatorChangeTwo
. react-router-dom
, то заменить BrowserRouter
на HashRouter
.