I don’t understand why the setProfile(member[0]) return the error:
TypeError: Cannot read properties of undefined (reading ‘0’)
'use client';
import { createContext, useContext, useEffect, useState } from "react";
import { I4TKnetworkAddress, I4TKnetworkABI } from "@/constants";
import { useAccount, useReadContract } from 'wagmi'
import {config} from '@/app/RainbowKitAndWagmiProvider.js'
const AppContext = createContext({});
export const AppContextProvider = ({ children }) => {
const { address } = useAccount()
const [profile, setProfile] = useState('');
const { data: member , isSuccess, refetch : refetchProjects} = useReadContract({
abi: I4TKnetworkABI,
address: I4TKnetworkAddress,
functionName: 'Members',
args: [address],
});
useEffect(() => {
console.log(member);
console.log(member[0]);
// setProfile(member[0])
}, [isSuccess]);
return (
<AppContext.Provider value={{
address,
profile,
}}>
{children}
</AppContext.Provider>
);
};
export const useAppContext = () => useContext(AppContext);
the console.log(member) returns :
”’
(2) [2, true]
0: 2
1: true
length: 2
[[Prototype]]: Array(0)
”’
thnks for your help
New contributor
jisse diouss is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.