SHOW CREATE TABLE table_name
$dbh = new PDO('mysql:host=...;charset=utf8mb4');
$mysqli->set_charset('utf8mb4');
default_charset = "utf-8"
в php.ini. header('Content-Type: text/html; charset=utf-8');
import format from "date-fns/format";
import frLocale from "date-fns/locale/fr";
import ruLocale from "date-fns/locale/ru";
import enLocale from "date-fns/locale/en-US";
import DateFnsUtils from "@date-io/date-fns";
import MoreIcon from "@material-ui/icons/MoreVert";
import React, { useState, useCallback } from "react";
import { IconButton, Menu, MenuItem } from "@material-ui/core";
import { DatePicker, MuiPickersUtilsProvider } from "@material-ui/pickers";
const localeMap = {
en: enLocale,
fr: frLocale,
ru: ruLocale,
};
class RuLocalizedUtils extends DateFnsUtils {
getCalendarHeaderText(date) {
return format(date, "LLLL", { locale: this.locale });
}
getDatePickerHeaderText(date) {
return format(date, "dd MMMM", { locale: this.locale });
}
}
class FrLocalizedUtils extends DateFnsUtils {
getDatePickerHeaderText(date) {
return format(date, "d MMM yyyy", { locale: this.locale });
}
}
const localeUtilsMap = {
en: DateFnsUtils,
fr: FrLocalizedUtils,
ru: RuLocalizedUtils,
};
const localeFormatMap = {
en: "MMMM d, yyyy",
fr: "d MMM yyyy",
ru: "d MMM yyyy",
};
const localeCancelLabelMap = {
en: "cancel",
fr: "annuler",
ru: "отмена",
};
function DateFnsLocalizationExample() {
const [locale, setLocale] = useState("ru");
const [anchorEl, setAnchorEl] = useState(null);
const [selectedDate, handleDateChange] = useState(new Date());
const handleMenuOpen = useCallback(e => {
e.stopPropagation();
setAnchorEl(e.currentTarget);
}, []);
const selectLocale = useCallback(locale => {
setLocale(locale);
setAnchorEl(null);
}, []);
return (
<MuiPickersUtilsProvider utils={localeUtilsMap[locale]} locale={localeMap[locale]}>
<DatePicker
value={selectedDate}
onChange={handleDateChange}
format={localeFormatMap[locale]}
cancelLabel={localeCancelLabelMap[locale]}
InputProps={{
endAdornment: (
<IconButton
aria-label="Select locale"
onClick={handleMenuOpen}
aria-owns={anchorEl ? "locale-menu" : undefined}
>
<MoreIcon />
</IconButton>
),
}}
/>
<Menu
id="locale-menu"
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={() => setAnchorEl(null)}
>
{Object.keys(localeMap).map(localeItem => (
<MenuItem
key={localeItem}
selected={localeItem === locale}
onClick={() => selectLocale(localeItem)}
>
{localeItem}
</MenuItem>
))}
</Menu>
</MuiPickersUtilsProvider>
);
}
export default DateFnsLocalizationExample;
const [data, setData] = useState(null);
useEffect(() => {
const controller = new AbortController()
fetchData(controller.signal).then(setData)
return () => controller.abort()
}, [fetchData, setData])
const data = useMemo(() => array.map(mapper).filter(predicate).reduce(reducer), [array])
const handler = useCallback(() => {
// что-то сделать
}, [])
useEffect(() => {
handler(value)
// если не использовать useCallback, эффект будет срабатывать постоянно
}, [handler, value])
Как в юнит тестах тестить нажатие на кнопку? Или мы можем тестить только функцию-обработчик?
/common
/api
/components
/ducks
/entities
/sagas
/selectors
/utils
/features
/Feature1
/Feature2
/Feature3
/Feature4
...
/FeatureN
/Main
/pages
index.js
App.js
routes.js
rootReducer.js
rootSaga.js
store.js
/Auth
/pages
index.js
App.js
routes.js
rootReducer.js
rootSaga.js
store.js
...
/features
/Accounts
/components
index.js
accountsDucks.js
accountsSaga.js
accountsSelectors.js
accountsApi.js
Accounts.js
AccountsContainer.js
/actions
/common
/components
/core
/Feed
/Profile
...
/constraints
/containers
/entries
/locales
/pages
/reducers
/utils
...