我有那些类型
interface UsersTokenInfoProps {
selectedToken: String,
loadRedisKey: Function
}
这些是我的分配器和映射状态
const mapStateToProps = (state) => state;
function mapDispatchToProps(dispatch) {
return {
loadRedisKey: async (el) => {
dispatch(loadRedisKey(el));
}
}
}
这是我的组成部分
export const UsersTokenInfo: React.FC<UsersTokenInfoProps> = (props: UsersTokenInfoProps) => {
React.useEffect(() => {
getTokenInfo(props.selectedToken);
}, [props.selectedToken])
const getTokenInfo = id => {
if (id != "") {
props.loadRedisKey(id);
}
}
React.useEffect(() => {
console.log("........")
console.log(props.redisReducer.decodedRedisKey) //error redisreducer does not exist on type UsersTokenInfoProps
console.log("........")
}, [props.redisReducer.decodedRedisKey])
.....
这是我的减速器
import { Action } from "../store/types";
import { GET_REDIS_KEY_INFO } from "../constants/actionTypes";
const defaultState = {
decodedRedisKey: {}
}
const redisReducer = (state = defaultState, action: Action) => {
switch (action.type) {
case GET_REDIS_KEY_INFO: {
return {
...state,
decodedRedisKey: action.payload
}
}
default:
return {
...state,
};
}
}
export default redisReducer;
所以我不明白如何在我的reducer中读取状态,因为我不知道如何键入它,所以ts出错了