简体   繁体   English

React js - 如何制作组件上下文

[英]React js - how to make a component context

How do i make a react component context?我如何制作反应组件上下文?

I manage to make it working, but happens that i`m unable to achieve this by the lack of understanding react.我设法使它工作,但碰巧我由于缺乏理解反应而无法实现这一目标。

I'll share my code.我会分享我的代码。 I want to do a 4 page components, apearing inside the main page.我想做一个 4 页面组件,在主页面内显示。 And as soon as i click on a new link, the set of 4 pages, change to a new set.一旦我点击一个新链接,这组 4 个页面,就会变成一个新的集合。 But not using routing, only using context.但不使用路由,只使用上下文。

Is that possible?那可能吗? Link to sample on code sandbox: Codesandbox example代码沙箱示例链接: Codesandbox 示例

I think your case is valid.我认为你的情况是有效的。 But a hook isn't a context, so you are right, you need to turn useTransistorInit into a context like object.但是钩子不是上下文,所以你是对的,你需要将useTransistorInit变成像 object 这样的上下文。

I recently helped someone with similar concern, you can take a look here.我最近帮助了一个有类似问题的人,你可以看看这里。 How to Get Back Data which was get filtered (ReactContextAPI) 如何取回被过滤的数据(ReactContextAPI)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 这是React.js组件上下文 - React.js Component context of 'this' React js - 如何在测试组件时模拟上下文 - React js - How to mock Context when testing component 如何使 js 为 React 中的组件内部组件工作? - How to make js working for component inside component in React? React js。 如何使用这种结构制作组件: <Component> 组件说明 </Component> - React js. How to make a component with this structure: <Component> description of the component </Component> 如何在 Material UI (React JS) 中根据需要制作“选择”组件 - How to make a 'Select' component as required in Material UI (React JS) 如何在 React JS 中制作相同的 URL 方案但不同的路线和组件 - How to make same URL scheme but different route and component in React JS 如何在react.js中滚动显示/隐藏组件 - How to make a component show/hide on scroll in react.js 如何仅在具有 Typescript 的容器组件的上下文中使用 React 道具? - How do I make a React prop only required when used in the context of a Container component with Typescript? 如何将 function 从 FUNCTIONAL 传递给 CLASS 组件并在渲染外部访问它(没有 prop ),在反应 js 中使用上下文? - How to pass function from FUNCTIONAL to CLASS component and access it outside of render( without prop ), using context in react js? 如何将上下文使用者传递给仅由React Router呈现的组件(Event.js)? - How to pass context consumer to Component (Event.js) rendered by React Router only?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM