Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Create, Edit and Show cannot be used outside of a ResourceContextProvider #5730

Conversation

fzaninotto
Copy link
Member

Closes #5662

Although the <Create>, <Edit> and <Show> components were never meant to be used outside of <Resource> props, developers have taken the habit to use them in standalone, passing the resource as prop. The fact that it worked was undocumented, but intuitive and practical.

The introduction of the <ResourceContextProvider> broke this. An attempt to use <Create resource="foos"> fails - the user has to wrap the component in a <ResourceContextProvider>.

We recognize that <Create>, <Edit> and <Show> should be usable outside of <Resource>, so they should be able to create their own <ResourceContextProvider> when passed a resource prop.

@fzaninotto fzaninotto added the RFR Ready For Review label Jan 3, 2021
@fzaninotto fzaninotto added this to the 3.11.2 milestone Jan 3, 2021
<CreateContextProvider value={controllerProps}>
<CreateView {...props} {...controllerProps} />
</CreateContextProvider>
);
return props.resource ? (
Copy link
Member Author

@fzaninotto fzaninotto Jan 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'v considered extracting this duplicated logic to a dedicated component, like so:

const ConditionalWrapper = ({ condition, wrapper, children }) => 
  condition ? wrapper(children) : children;

...

<ConditionalWrapper
   condition={props.resource}
   wrapper={children => <ResourceContextProvider value={props.resource}>{children}</ResourceContextProvider>}
>
    <CreateContextProvider value={controllerProps}>
        <CreateView {...props} {...controllerProps} />
    </CreateContextProvider>
</ConditionalWrapper>

But I find it less legible. Besides, the duplication is only a few lines.

@fzaninotto fzaninotto force-pushed the fix-Create-Edit-Show-cannot-be-used-outside-ResourceContextProvider branch from e5bf65a to dbe1e42 Compare January 4, 2021 08:58
@fzaninotto
Copy link
Member Author

rebased

@djhi djhi merged commit fe6f771 into master Jan 4, 2021
@djhi djhi deleted the fix-Create-Edit-Show-cannot-be-used-outside-ResourceContextProvider branch January 4, 2021 09:31
@maaarghk maaarghk mentioned this pull request Jan 9, 2021
@koaladlt
Copy link

koaladlt commented Sep 20, 2021

Do we have any updates on this? Is there a way to use Create with a different endpoint?

@fzaninotto
Copy link
Member Author

@koaladlt The updates on this PR is that it's merged and published in 3.11, as the "Milestone" zone on the right column suggests.

About your other question, please consider asking it on stackOverflow. As explained in the issue template, we don't do free support on gitHub issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow passing a custom resource prop to Create / Edit
3 participants