React
- 855 ответов
- 0 вопросов
1139
Вклад в тег
const
вместо let
для определения переменных которые не переопределяются в коде. Это помогает снизить когнитивную нагрузку с человека читающего код и негласный стандарт в React разработке.{
isModal
? <Route path="/auth" component={AuthPopup} />
: null
}
{isModal && <Route path="/auth" component={AuthPopup} />}
function mapDispatchToProps(dispatch) {
return {
autoLogin: () => dispatch(autoLogin()),
getBrowser: () => dispatch(getBrowser()),
getMedia: () => dispatch(getMedia())
}
}
const mapDispatchToProps = {
autoLogin,
getBrowser,
getMedia,
};
& label {}
& input {}
& span {}
import {combineReducers} from 'redux';
import photoReducer from './photoReducer';
import authReducer from './authReducer';
import globalReducer from './globalReducer';
export default combineReducers({
photoReducer, authReducer, globalReducer
})
import {combineReducers} from 'redux';
import photo from './photoReducer';
import auth from './authReducer';
import global from './globalReducer';
export default combineReducers({
photo,
auth,
global,
});
return e === 'invalid-email' ? 'Неверно указан e-mail'
: e === 'user-not-found' ? 'Указанный e-mail на найден'
: e === 'wrong-password' ? 'Неверный пароль'
: e === 'email-already-in-use' ? 'Указанный e-mail уже используется'
: e === 'network-request-failed' ? 'Нет подключения к интернету'
: e === 'operation-not-allowed' ? 'Произошла ошибка, попробуйте снова'
: e === 'popup-closed-by-user' ? 'Окно авторизации закрыто пользователем'
: e === 'account-exists-with-different-credential' ? 'Аккаунт уже существует с другими данными, используйте другой способ авторизации'
: e
switch case
import {SET_ACTIVE, CHANGE_VALUE, SET_DEFAULT, UPLOAD, UPDATE_IMAGE, SET_IMAGE_ERROR, SET_LIKE, SET_COMMENT, ADD_ARTICLE_SUCCESS, FETCH_ARTICLES_START, FETCH_ARTICLES_SUCCESS, FETCH_ARTICLES_ERROR} from '../actions/actionTypes';
import {
SET_ACTIVE,
CHANGE_VALUE,
SET_DEFAULT, UPLOAD,
UPDATE_IMAGE,
SET_IMAGE_ERROR,
SET_LIKE,
SET_COMMENT,
ADD_ARTICLE_SUCCESS,
FETCH_ARTICLES_START,
FETCH_ARTICLES_SUCCESS,
FETCH_ARTICLES_ERROR,
} from '../actions/actionTypes';
function mapStateToProps(state) {
return {
browser: state.globalReducer.browser
}
}
const mapStateToProps = state => ({
browser: browserSelector(state),
});
export const withLatest = request => {
let last = 0;
return (...args) =>
new Promise((resolve, reject) => {
const current = ++last;
request(...args)
.then(res => resolve({ isLatest: current === last, res }))
.catch(err => reject({ isLatest: current === last, err }));
});
};
export const withLatest = request => {
let last = 0;
return async (...params) => {
const current = ++last;
try {
const res = await request(...params);
return { isLatest: current === last, res };
} catch (err) {
throw { isLatest: current === last, err };
}
};
};
import Api from '../api';
import { withLatest } from '../utils';
const withLatestFetchData = withLatest(Api.fetchData);
export const fetchData = query => async (dispatch, state) => {
dispatch({ type: "LOADING_DATA" });
try {
const { isLatest, res } = await withLatestFetchData(query);
if (isLatest) {
dispatch({ type: "DATA_SUCCESS", payload: res });
}
} catch ({ isLatest, err }) {
if (isLatest) {
console.log(err);
}
}
};