S
Size: a a a
S
SB
build
и тупо грузим её на сервер (а наш сервер уже нужные данные прокидывает в эти странички).next
в зависимостях к серверу.SB
req
или в res
?page.render(req, res);
I
🦜
req
или в res
?page.render(req, res);
SB
getInitialProps
(вот и встал в ступор...)I
KS
// REDUCERS
export const reducer = (state = exampleInitialState, action) => {
if (action.type === 'GET_USERS') {
return{
...state,
users: action.payload,
};
} else {
return state;
}
};
// ACTIONS
export const getUsers = () => dispatch => {
axios.get('https://jsonplaceholder.typicode.com/users')
.then(res=>{
dispatch({
type: 'GET_USERS',
payload: res.data
})
})
.catch(err => console.log(err))
};
// Using
class Users extends React.Component {
static getInitialProps ({ reduxStore, req }) {
const isServer = !!req;
// DISPATCH ACTIONS HERE ONLY WITH `reduxStore.dispatch`
reduxStore.dispatch(getUsers(isServer));
return {}
}
T
I
BB
// REDUCERS
export const reducer = (state = exampleInitialState, action) => {
if (action.type === 'GET_USERS') {
return{
...state,
users: action.payload,
};
} else {
return state;
}
};
// ACTIONS
export const getUsers = () => dispatch => {
axios.get('https://jsonplaceholder.typicode.com/users')
.then(res=>{
dispatch({
type: 'GET_USERS',
payload: res.data
})
})
.catch(err => console.log(err))
};
// Using
class Users extends React.Component {
static getInitialProps ({ reduxStore, req }) {
const isServer = !!req;
// DISPATCH ACTIONS HERE ONLY WITH `reduxStore.dispatch`
reduxStore.dispatch(getUsers(isServer));
return {}
}
BB
// REDUCERS
export const reducer = (state = exampleInitialState, action) => {
if (action.type === 'GET_USERS') {
return{
...state,
users: action.payload,
};
} else {
return state;
}
};
// ACTIONS
export const getUsers = () => dispatch => {
axios.get('https://jsonplaceholder.typicode.com/users')
.then(res=>{
dispatch({
type: 'GET_USERS',
payload: res.data
})
})
.catch(err => console.log(err))
};
// Using
class Users extends React.Component {
static getInitialProps ({ reduxStore, req }) {
const isServer = !!req;
// DISPATCH ACTIONS HERE ONLY WITH `reduxStore.dispatch`
reduxStore.dispatch(getUsers(isServer));
return {}
}
KS
Fv
🦜
А
S
Travels.getInitialProps = async ({ query }) => {
const res = await axios({
get: 'get',
url: '/api/pages',
});
return { article: query.article, pages: res.data };
};
connect ECONNREFUSED 127.0.0.1:80
А
S
Travels.getInitialProps = async ({ query }) => {
const res = await axios({
get: 'get',
url: '/api/pages',
});
return { article: query.article, pages: res.data };
};
connect ECONNREFUSED 127.0.0.1:80
G