api를 불러와서 테이블을 만들려고 하는데 recoil을 이용해 상태관리를 하려고 합니다.
interface studentList {
code: number;
response: string;
data: studentsTypes;
}
export function studentList(): Promise<studentList> {
const accessToken = getLocalStorageValue("token") ?? "";
return fetch(`${BASE_URL}/api/students/1`, {
headers: {
Authorization: accessToken,
},
}).then((response) => response.json());
}
일단 이렇게 api를 불러왔는데 더 데이터들을 어떻게 불러와서 표를 만들어야할까요..
selector를 이용해서 불러오면 되는걸까요? ㅜㅜ
import { atom } from "recoil";
export interface studentsTypes {
studentId: string;
name: string;
school: string;
grade: number;
subject: string;
}
export interface studentDataTypes {
maxPage: number;
data: studentsTypes[];
}
export const studentsAtom = atom<studentDataTypes>({
key: "students",
default: {
maxPage: 1,
data: [],
},
});
아톰은 이렇게 작성했습니다..!!