module.exports = {
module: {
rules: [
{
test: /\.(png|jpe?g|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
},
},
],
},
],
},
};
import React from 'react';
import image from './image.png';
const Example = () => (
<img src={image} />
);
import React from 'react';
const Example = () => (
<img src={require('./image.png')} />
);
import React from 'react';
import data from './products.json';
const List = () => (
<ul>
{data.map(product => (
<li key={product.id}>{product.title}</li>
)}
</ul>
);
import React from 'react';
import PropTypes from 'prop-types';
// ...
Slider.propTypes = {
slidePerView: PropTypes.string,
slidesPerGroup: PropTypes.string,
loop: PropTypes.string,
};
// ...
const CTX = React.createContext();
const App = () => (
<CTX.Provider value={ctx}>
<MyComponent />
</CTX.Provider>
);
const CTX = React.createContext(ctx);
const App = () => (
<MyComponent />
);
useEffect(() => {
doSomething();
}, [match.params.id]);
<Redirect
to={{
pathname: '/login',
state: { referrer: props.history.location.pathname }, // или `/products/${slug}`
}}
/>
class Login extends React.Component {
onLoginSuccess() {
const { history } = this.props;
const { state } = history.location;
const location = (state && state.referrer) || '/';
history.push(location);
}
/* ... *.
}
Поскольку Header не участвует в роутинке я не могу от него передать в Search props.history и уже на нем вызвать пуш а не как сейчас на прямую!
export default withRouter(Header);
const Foo = ({ data }) => {
const dispatch = useDispatch();
useEffect(() => {
dispatch(func(data));
}, [data]);
return (/* ... */);
}
const PrivateRoute = ({ component: Component, render, isSignedIn, ...rest }) => (
<Route
{...rest}
render={props => {
if (!isSignedIn) return (
<Redirect
to={{
pathname: '/login',
state: { referrer: props.history.location.pathname },
}}
/>
);
if (render) return render({ ...props });
return <Component {...props} />;
}}
/>
);
const mapStateToProps = (state) => ({
isSignedIn: isSignedInSelector(state),
});
export default connect(mapStateToProps)(PrivateRoute);