混音装载机返回“未定义”
我为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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这甚至不是问题,而是编写方法的盗用。
对于任何可能犯这种愚蠢错误的人,请确保您在路线中打电话给这些混音帮助者。
就像我尝试这样做一样,它在任何组件文件中都无法使用。
加载程序和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.
我还想指出,应该像这样导入LoaderFunction:
I would also like to point out that LoaderFunction should be imported like this: