英文:
Remix run: How to pass prop data from a parent component to the loader/action function of child components?
问题
使用Remix run,是否可以将父组件的属性数据传递到子组件的加载器/操作函数中?
如果不行,是否有人知道在子组件的加载器/操作函数中获取父组件数据的方法?
非常感谢,
J
英文:
Using Remix run, is it possible to pass prop data from a parent component inside the loader/action function of child components?..
If not does anyone know of a method to get parent data inside the loader/action functions of child components?
Many thanks,
J
答案1
得分: 3
在Remix中,加载器是并行运行的,因此无法将数据从父加载器传递给子加载器。这是为了防止抓取瀑布和提高性能。
一旦数据被抓取,您可以从您的UI组件中访问它。使用useMatches
或useRouteLoaderData
来从另一个路由加载器获取数据。
注意:他们正在努力添加中间件支持,以便您可以在加载器之前和之后调用一个函数。然后,通过
context
将数据传递给您的加载器。
英文:
In Remix, loaders are run in parallel, so there isn't a way to pass data from a parent loader to a child loader. This is to prevent fetch waterfalls and improve performance.
Once the data is fetched, you can access it from your UI components. Use useMatches
or useRouteLoaderData
to get data from another route loader.
> NOTE: they are working on adding middleware support so that you can have a function called before and after your loaders. You then pass that data via context
to your loaders.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论