reactjs - 如何将道具传递给组件(使用钩子),该组件用于从渲染道具编程中获取道具
问题描述
我收到了一个使用渲染道具和路线的程序:
<MyRoute exact module="basic" action="show" resource="Document" path="..." component={MyComponent} />
然后 MyRoute 会:
const MyRoute = ({ ...props }) => {
const { component: MyComponent, ...otherProps } = props;
return (
<Route
{...otherProps}
render={rest =>
<MyComponent {...rest} />
}
/>
);
};
export default MyRoute;
otherProps 和 rest 的 console.log 是:
Rest:
history: {length: 1, action: "POP", location: {…}, createHref: ƒ, push: ƒ, …}
location: {pathname: "/document_preview/335", search: "?employee=82", hash: "", state: undefined}
match: {path: "/document_preview/:id", url: "/document_preview/335", isExact: true, params: {…}}
staticContext: undefined
[[Prototype]]: Object
------------------------------------------
otherProps:
action: "show"
computedMatch: {path: "/document_preview/:id", url: "/document_preview/335", isExact: true, params: {…}}
exact: true
location: {pathname: "/document_preview/335", search: "?employee=82", hash: "", state: undefined}
module: "basic"
path: "/document_preview/:id"
resource: "Document"
[[Prototype]]: Object
我需要能够在模态中安装整个组件,我需要能够执行和交付它需要的所有道具,而不使用渲染道具和路由,只使用钩子
你认为我在这里的选择是什么?
拉斐尔
解决方案
推荐阅读
- python - 在 jupyter note 中提供数据路径时遇到一些问题
- python-3.x - 网络快捷方式没有做我想做的事
- laravel - 流明 8.2 中的错误 - “找不到类 '\App\User'”
- javascript - 在 express.js 中未找到错误 MODULE
- nestjs - NestJS 中的模型与 DTO
- sql - SQL中的三向差异
- git - 在 repo 分支重组后将已提交的更改从已删除的分支移动到新分支
- ansible - Rundeck - 使用资源 yaml 文件中定义的节点运行命令/作业的问题
- visual-studio-code - 一些 Emmet 代码在 vscode 和 atom IDE 中不起作用
- java - 如何在 Java 中序列化和反序列化对象?