为什么以下代码不起作用?
是否可以使用代理对象作为密钥?
from django.utils.translation import ugettext_lazy as _
ABBREVIATIONS = {
_('tr.'): 'transitive'
}
答案 0 :(得分:1)
不能使用代理对象。您必须将键转换为有效类型,例如转换为字符串:
import React, { createContext, useReducer, useContext } from 'react';
import Reducer, { initialState } from "./reducer";
export type Todo = {
id: number;
text: string;
done: boolean;
};
export type TodosState = Todo[];
const ToDosContext = createContext<Array<Todo> | any>(null);
const ToDosProvider = ({ children }: { children: React.ReactNode }) => {
const [state, dispatch] = useReducer(Reducer, initialState);
return (
<ToDosContext.Provider value={{ state, dispatch }}>
{children}
</ToDosContext.Provider>
);
};
export const useTodosDispatch = () => {
const { dispatch } = useContext(ToDosContext);
return dispatch;
};
export const useTodosState = () => {
const { state } = useContext(ToDosContext);
return state;
};
export default ToDosProvider;