Reuse cells in multiple components

Hi all,

Just getting started with Redwood and enjoying it so far! I’m currently trying to create a form which uses data from the db to populate a select field - “category”. I’ve already scaffolded a categories page etc. and therefore have a categories cell for that (which renders the list view on success).

I was wondering whether there was any way to reuse this cell, or if it’s best to create a new one to render the select field (even though it will be getting the same data), or even if there’s a better way.

Thanks!

If you’re using multiple components in the same cell, that’s not an issue. You can have many components in that cell that is getting data passed down from the cell query.

Thanks @Cromzinc, although I wouldn’t want both the categories list component and select field component rendered at the same time. Are you suggesting I use props or similar to conditionally render the desired component?

Currently I’ve gone for the second option of creating a separate cell for the select field. Seems a bit of duplication but perhaps not a huge problem…

You could extract the gql query and reuse/import that in your CategoriesCell that renders the list view and select list (if you want).

But, I suggest having a separate cell CategeoriesSelectList that fetches and renders the select list in the Success component.

1 Like