Skip to content

Add render prop to page and reference base components#10832

Merged
fzaninotto merged 41 commits intonextfrom
marmelab/renderprops-with-context
Jul 21, 2025
Merged

Add render prop to page and reference base components#10832
fzaninotto merged 41 commits intonextfrom
marmelab/renderprops-with-context

Conversation

@ThieryMichel
Copy link
Copy Markdown
Contributor

@ThieryMichel ThieryMichel commented Jul 8, 2025

Problem

When doing custom UI, having to read the RecordContext or ListContext forces to create a separate component, or to use WithRecord and WithListContext. For really custom UIs, it feels like an unnecessary indirection.

const PagesList = () => (
   <List>
       <ul>
           <WithListContext render={({ data }) =>
               data.map(page => (
                   <li key={page.id}>
                       <Link to={page.url}>{page.title}</Link>
                   </li>
               ))
           } />
       </ul>
   </List>
);

Solution

Support a render prop that renders inside the created context, but also passes the context as argument.

const PagesList = () => (
   <List render={({ data }) =>
      <ul>{data.map(page => (
            <li key={page.id}>
               <Link to={page.url}>{page.title}</Link>
            </li>
      ))}</ul>} />
   </List>
);

This prop is optional. When absent, the component falls back to using children .

Concerned components:

  • ListBase (supersedes ListController)
  • InfiniteListBase
  • EditBase(supersedes EditController)
  • CreateBase (supersedes CreateController)
  • ShowBase (supersedes ShowController)
  • ReferenceFieldBase
  • ReferenceManyFieldBase
  • ReferenceArrayFieldBase (to be introduced)
  • ReferenceOneFieldBase

Add stories and documentation for these props.

Out of scope

  • ReferenceXXXInput components
  • RA Mui components
  • EE components
  • ListIterator / SingleFieldListBase (cf (1) Add a headless version of SingleFieldList In development 🔥)

How To Test

Describe the steps required to test the changes

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date

Also, please make sure to read the contributing guidelines.

@ThieryMichel ThieryMichel force-pushed the marmelab/renderprops-with-context branch from b38995a to 70b260c Compare July 11, 2025 15:37
@fzaninotto fzaninotto changed the title Marmelab/renderprops with context Add render prop to page and reference base components Jul 21, 2025
@fzaninotto fzaninotto merged commit d027119 into next Jul 21, 2025
15 checks passed
@fzaninotto fzaninotto deleted the marmelab/renderprops-with-context branch July 21, 2025 15:32
@fzaninotto fzaninotto added this to the 5.10.0 milestone Jul 21, 2025
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.

3 participants