混音装载机返回“未定义”

发布于 2025-01-25 16:11:33 字数 719 浏览 2 评论 0原文

我为Remix进行了一次很好的首次尝试,我认为我喜欢它的数据处理方法。但是,我正面临着一个来自装载机包装器“未定义”的数据的问题。

import { LoaderFunction } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import axios from 'axios';
const url = 'https://jsonplaceholder.typicode.com/users'

export async function Members(){
const {data} = await axios.get(url);
 return data
} //I am sure it returns the expected data when I call on this function.

export const loader: LoaderFunction = async () => {
const response = await Members()
 return response
};

export const Architects = () => {
  const members = useLoaderData()
  console.log(members)

  return (
    ....
  )
}

我在这里真的想念什么?我会在这里感谢指针。使用不是混音的其他基于反应的方法是不明智的

I am giving remix a good first-time try and I think I love its approach to data handling. However, I am facing an issue with data returning "undefined" from the loader wrapper.

import { LoaderFunction } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import axios from 'axios';
const url = 'https://jsonplaceholder.typicode.com/users'

export async function Members(){
const {data} = await axios.get(url);
 return data
} //I am sure it returns the expected data when I call on this function.

export const loader: LoaderFunction = async () => {
const response = await Members()
 return response
};

export const Architects = () => {
  const members = useLoaderData()
  console.log(members)

  return (
    ....
  )
}

What am I really missing here? I'll appreciate a pointer here. It wouldn't be wise to use other react based approaches that isn't remix's

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

卷耳 2025-02-01 16:11:33

这甚至不是问题,而是编写方法的盗用。

对于任何可能犯这种愚蠢错误的人,请确保您在路线中打电话给这些混音帮助者。

就像我尝试这样做一样,它在任何组件文件中都无法使用。
加载程序和USELOADERDATA以及混音的大多数方法主要是服务器。上述代码没有错。我所说的是问题所在。

感谢所有观看此事的人。

This isn't even an issue but a misappropriation in writing the methods.

For anyone who might make this kind of silly mistake, please, do ensure you are calling these remix helpers in your ROUTES.

It will not work in any of your components files just like I tried to do it.
The loader and useLoaderData and most of the remix's methods are mostly serverside. Nothing is wrong with the above code. Where I called it is what the problem was.

Thanks to all those who viewed this.

神经大条 2025-02-01 16:11:33

我还想指出,应该像这样导入LoaderFunction:

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

I would also like to point out that LoaderFunction should be imported like this:

import type { LoaderFunction } from "@remix-run/node";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文