2025-03-06

今のフロントエンドコードを書いてるとCOBOLの頃を思い出す

constを上から順にひたすら羅列していく感じがなんかね

と思うオブジェクト指向おじさんなのだった

以下chatgptによるremixjsの例

import { useEffect, useState } from "react";

import { json } from "@remix-run/node";

import { useLoaderData } from "@remix-run/react";

export const loader = async () => {

const response = await fetch("https://api.example.com/data");

const data = await response.json();

return json({ initialData: data });

};

export default function Index() {

const { initialData } = useLoaderData();

const [data, setData] = useState(initialData);

useEffect(() => {

const fetchData = async () => {

const response = await fetch("http://api.com/get");

const newData = await response.json();

setData(newData);

};

fetchData();

}, []);

if (initialData.value === null || data.value === null) {

return (

データの取得に失敗しました。

);

}

return (

<h1>Remix: SSR + クライアント処理</h1>

サーバーサイドの初期データ: {initialData.value}

クライアント更新したデータ: {data.value}

);

}

  • 全部バラバラのぱーつだし プロダクションだとステート管理と非同期の嵐だから上から実行系とは全然ちがうぞ

  • Reactじゃなくて大昔のClassicASP+VBとかだとそういう上から実行みたいな感はある

記事への反応(ブックマークコメント)

ログイン ユーザー登録
ようこそ ゲスト さん