const action = value => (dispatch, getState) => {
const otherValue = otherValueSelector(getState());
const payload = calculate(value, otherValue);
dispatch(otherAction(payload));
};
export const addTrack = (track) => store.dispatch({ type: ADD_TRACK, payload: { track } });
const socket = io('/path');
const useFetch = (url, options) => {
const [data, setData] = useState(null);
const [error, setError] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const fetchData = async () => {
try {
setIsLoading(true);
const res = await fetch(url, options);
const json = await res.json();
setData(json);
setIsLoading(false);
} catch (error) {
setError(error);
setIsLoading(false);
}
};
useEffect(() => {
fetchData();
});
return [
data,
isLoading,
error,
fetchData,
];
};
const Example = ({ slug }) => {
const [ product, isLoading, error, fetchFn ] = useFetch(`/api/product/${slug}`);
if (isLoading) return <Preloader />;
if (error) return <Error error={error} tryAgainFn={fetchFn} />;
if (!product) return <NotFound />;
return <Product product={product} />
};
после некоторого времени обнаружил что вебпак изменяет путь
То есть
путь import video from '../../img/video/mainstream.mp4'
он видит как Video /static/media/mainstream.bbae5fec.mp4
<video src={require('../../img/video/mainstream.mp4')} />
onChange={(e) => this.limitSwitchHandler(e, row.id)}
createLimitPerDayHandler = (rowId) => (e) => { ... };
const Header = ({ children }) => (
<div className="navHeader">
{children}
</div>
);
<Header>
<Top />
</ Header>
const Header = ({ top }) => {
const HeaderTop = top || Top;
return (
<div className="navHeader">
<HeaderTop />
</div>
);
};
<Header /> // используем компонент по-умолчанию Top
<Header top={OtherTopCompnent} /> // используем другой компонент
const MovieList: React.FC<MovieListPropsType> = ({ ... }) => { ... };
const mapStateToProps = createStructuredSelector({ ... });
const mapDispatchToProps = { ... };
export default connect(mapStateToProps, mapDispatchToProps)(MovieList);