GithubHelp home page GithubHelp logo

Comments (1)

sueCalystegia00 avatar sueCalystegia00 commented on August 21, 2024

88bf971

ストレージから取得

const sessionQuestionsData = sessionStorage.getItem(STORAGE_KEY_QUESTIONS); // セッションストレージから質疑応答情報を取得
const [questions, setQuestions] = useState<Questions>(
    sessionQuestionsData ? JSON.parse(sessionQuestionsData) : {} // セッションストレージに質疑応答情報があればそれを利用,なければ空オブジェクトを利用
);

ストレージに追加

const getQuestionsDataHandler = async () => {
    await axios.get(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v2/questions/list`, {
        params: { startIndex: startIndex },
    })
    .then((response: AxiosResponse<Questions>) => {
        const { data } = response;
+	// セッションストレージに保存
+	sessionStorage.setItem(
+	    STORAGE_KEY_QUESTIONS,
+	    JSON.stringify({ ...questions, ...data })
+	);
	setQuestions({ ...questions, ...data }); // stateを更新
	Object.keys(data).length < 30 && setIsHasMore(false); //取得数が30件未満なら追加取得できないことを示す
    })
    .catch((error: AxiosError) => {
        alert("サーバーでエラーが発生しました.");
	console.error(error);
    });
};

from susan-next.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.