'How to create boundary in React?
I have a form and a list. I want to put them inside a parent component (a boundary) and I want to change their form and behavior based on the detection of the presence of the boundary.
Here's my idea:
const ParentChildrenPage = () => {
return <ParentChildren>
<ParentForm />
<ChildrenList />
</ParentChildren>
}
Here are some notes:
ParentFormwhen rendred by itself, has aCancelbutton that returns the user to the previous page. But when it's rendered inside theParentChildrenit should not show thatCancelbutton, and onSaveit should not navigate user to the previous page, but should stay in that page.ChildrenListhas aAddbutton on top of it. When shown by itself it navigates user to a child creation form. But when it detects that it's rendered insideParentChildrenitsAddbutton should show a dialog form.
Basically, I'm trying to create the notion of boundary and let children components detect that they are rendered inside that boundary and adjust their structure and behavior accordingly.
How can I do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
