-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
useRegisterResource is not exported #7623
Comments
Why did you use this hook? As far as I know, it was not documented anywhere - to put it otherwise, a private API. |
We se it to dynamically register resources so that all components of For example, we have a page for that displays AD account records and is routable via Inside Since it is not registered, some RA features that rely on "hasShow" or "hasList" do not work properly. For example, "ShowButton" does not work. |
Here is a component that we created that we use in custom routes, so that RA features work properly. /**
* This component will register resource in resource ResourceDefinitionContext in React-Admin
* If a resource is not registered in ResourceDefinitionContext, some generic functions in List, Create, Edit and Show will not work properly
* For example, Create button will be missing on List component
*
* @example
* <ResourceWithReg name='users' list={UserList} />
*/
export function ResourceWithReg(props: ResourceProps) {
const def: ResourceDefinitions = useResourceDefinitions()
const { name, create, edit, list, show, icon } = props
const hasList = !!list
const hasCreate = !!create
const hasEdit = !!edit
const hasShow = !!show
const registerResource = useRegisterResource()
const isRegistered = !!def[props.name]
useEffect(() => {
if (!isRegistered) {
console.debug(`Registering "${name}" resource`)
registerResource({ name, hasList, hasCreate, hasEdit, hasShow, icon })
}
}, [registerResource, isRegistered, name, hasList, hasCreate, hasEdit, hasShow, icon])
if (isRegistered) return <Resource {...props} />
else return null
}
export default ResourceWithReg |
An example of a page that we render under /ad_accounts/9513/show/ad_accounts_log/27075/show Change Log table is a List from Additional details are a record To make all features work properly, before we render |
An alternative solution is to update React-Admin's ` component to check if resource is registered, and register the resource before returning child components. |
@panfiva Here is the linked pull request, and the use case is mentioned there, #7455 You can still use the I also noticed the method is no longer exported when upgrading to 4.0.2. If we still want to support this use case we can add an example in documentation. |
I would like to have an ability to access as an alternative, can we modify thanks |
So the We still consider this hook internal API though, so we won't document it or support its usage outside of react-admin modules. The official way of adding resource at runtime is documented at https://marmelab.com/react-admin/Admin.html#declaring-resources-at-runtime. |
What you were expecting:
useRegisterResource should be exported in react-admin
What happened instead:
useRegisterResource is no longer exported in 4.0.2
Recevied error when importing useRegisterResource
Environment
The text was updated successfully, but these errors were encountered: