0
How to pass the value of the list and sector?
import React from "react";
interface Lista {
nome: string,
empresa: string,
ramal: number
}
const listaInicial: Lista = {
nome: "",
empresa: "",
ramal: 0
}
interface Props {
children: React.ReactNode
}
const ListaContext = React.createContext<Lista>(listaInicial);
export default function ListaProvider({children}: Props) {
const [lista, setLista] = React.useState<Lista[]>([]);
React.useEffect(() => {
setLista([
{
nome: "nome 1",
empresa: "matriz",
ramal: 2000
},
{
nome: "nome 2",
empresa: "matriz",
ramal: 2001
},
{
nome: "nome 3",
empresa: "sede",
ramal: 2002
},
{
nome: "nome 4",
empresa: "sede",
ramal: 2002
},
])
}, []);
return (
<ListaContext.Provider value={{lista, setLista}}>
{children}
</ListaContext.Provider>
)
}
I don’t understand your question
– novic
I got the answer in the English stackoverflow. Follow with the answer: https://stackoverflow.com/questions/62304400/how-pass-a-array-and-setarray-in-value-of-provider-react-typescript-context
– Bruno Henrique