如何将父组件的属性数据传递给子组件的加载器/操作函数?

huangapple go评论57阅读模式
英文:

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组件中访问它。使用useMatchesuseRouteLoaderData来从另一个路由加载器获取数据。

注意:他们正在努力添加中间件支持,以便您可以在加载器之前和之后调用一个函数。然后,通过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.

huangapple
  • 本文由 发表于 2023年2月14日 21:12:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75448365.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定