<script>window.__INITIAL_STATE__ = { ... }</script>
В чем может быть причина?
const mapStateToProps = state => { // принимаем аргумент
return {
name: state && state.name, // используем аргумент
};
};
const mapStateToProps = state => ({
name: state && state.name,
});
const someCall = () => async dispatch() => {
dispatch({type: Constant.SOME_OPERATION_1});
await dispatch(createAccount());
dispatch({type: Constant.SOME_OPERATION_2});
};
export const createAccount = () => async (dispatch) => {
await request api;
dispatch({type: SMTH});
await another request api;
dispatch({type: SMTH2});
}
export const createAccount = () => async (dispatch) => {
try {
await request api;
dispatch({type: SMTH});
await another request api;
dispatch({type: SMTH2});
catch (e) {
// handle error here
}
}
const Grid = React.forwardRef((props, ref) => (
<div ref={ref}>{props.children}</div>
));
export class MyComponent extends React.Component {
render() {
return (
<Grid innerRef={this.props.forwardRef} />
);
}
}
const Grid = props => (
<div ref={props.innerRef}>{props.children}</div>
);
import { render } from 'react-dom';
import {createStore} from "redux";
import rootReducer from "../reducers";
import Auth from './components/Auth';
const store = createStore(rootReducer);
render(
<Provider store={store}>
<BrowserRouter>
<Auth />
</BrowserRouter>
</Provider>,
document.getElementById('root'),
);
import React, {Component} from 'react';
import {connect} from 'react-redux';
class Auth extends Component {
render() {
return (
<Switch>
<Route exact path={this.props.api.signin} render={() => Test}/>
</Switch>
);
}
}
const mapStateToProps = state => ({
api: state.api,
});
export default connect(mapStateToProps)(Auth);
const fetchUsers = params => async dispatch => {
try {
const data = await Api.fetchUsers(params);
dispatch(fetchUsersSuccess(data));
} catch (e) {
dispatch(fetchUsersFail(e));
}
}
const mapDispatchToProps = {
getProducts,
};
const mapDispatchToProps = (dispatch, ownProps) => ({
getProducts: () => dispatch(getProducts()),
});
cosnt mapDispatchToProps = dispatch => bindActionCreators(
{
getProducts,
},
dispatch,
);
const mapDispatchToProps = (dispatch, ownProps) => ({
...bindActionCreators(
{
...productsActions,
...usersActions,
...ordersActions,
},
dispatch,
),
() => getSomeOther(ownProps.someProp),
notNeedsToWrapInDispatch,
})
const funcName = () = > dispatch => {
return dispatch({
type: NAME_TYPE,
payload: lol
});
}
Что значить dispatch в данном коде?
dispatch => {
return dispatch({
type: NAME_TYPE,
payload: lol
});
}
Почему мы его не передаем как аргумент в скобках?
const foo = (bar) => bar;
const foo = bar => bar;
const funcName = () = > ({
type: NAME_TYPE,
payload: lol,
});
export const actionFromA = data => async (dispatch) => {
dispatch(actionFromA());
}
store.dispatch({ type: 'action_name' });
dispatch(actionFromA());
store.dispatch({ /* объект возвращаемый actionFromA */ });