react-native - 在减速器函数 REACT NATIVE 中将变量包装在 {} 中意味着什么?
问题描述
我是 React native 的新手,我遇到了 reducer 函数的代码,但我对为什么“token”被括在括号中感到困惑。它是否将令牌变成动态的东西或其他东西?
有人可以解释为什么会这样吗?太感谢了!
/** The reducer is in charge of updating the app state based on the dispatched action. **/
//Action Types
export const CREDENTIALED = 'auth/CREDENTIALED';
export const RESET_DATA = 'auth/RESET_DATA';
export const initialState = {
isLoading: true,
token: null,
};
//REDUCER
const authReducer = (state = initialState, action) => {
switch (action.type) {
case CREDENTIALED: {
let {token} = action;
return {...state, isLoading: true, token};
}
case RESET_DATA: {
return {...state, ...initialState};
}
default:
return state;
}
};
export default authReducer;
解决方案
无论如何都不是反应本机专家,但看起来令牌只是从行动中解构出来的。大致相同:
const dict = {
"alpha": 'a',
"beta": 'b',
}
const {alpha} = dict
console.log(alpha) // you should expect "a" to be printed out
推荐阅读
- c# - 使用 Selenium 登录到 TextNow 的问题
- python - 在 DataFrame 中进行分组、求和、排序和选择
- javascript - 在 React 中测试 Actions、Reducers 和 Contexts
- karate - 从空手道 0.9.2 迁移到 0.9.3 问题 - javascript 评估失败
- python - 动态 sqlalchemy 查询
- ios - 无法通过 UIView xib 上的按钮显示 tableview
- php - 在 PHP 中将数据从一种格式转换为另一种格式
- php - 在 Laravel 6 中注销后无法登录
- php - PHP 从 UDP 套接字连续读取
- javascript - 如何在 html 文件中使用 Node.js Express 函数