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

feat(component): pass createElement and Fragment components #26

Closed
wants to merge 7 commits into from

Conversation

shortcuts
Copy link
Member

@shortcuts shortcuts commented May 27, 2021

Summary

Pass createElement and Fragment to the components returning a JSX.Element which ease the user-land code when using vanilla JavaScript.

JavaScript Example

relatedProducts({
  container: '#relatedProducts',
  searchClient,
  indexName,
  objectIDs: [selectedProduct.objectID],
  itemComponent({ item, createElement, Fragment }) {
    return createElement(Fragment, {}, createElement('span', {}, item.name));
  },
});

@shortcuts shortcuts marked this pull request as ready for review May 31, 2021 14:39
packages/js-recommendations/README.md Show resolved Hide resolved

import { ChildrenProps } from './types';
import { cx } from './utils';

export function DefaultChildren<TObject>(props: ChildrenProps<TObject>) {
if (props.recommendations.length === 0) {
return <props.Fallback />;
return <props.Fallback createElement={createElement} Fragment={Fragment} />;
Copy link
Member

Choose a reason for hiding this comment

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

We might want to pass createElement and Fragment in the FBT and RP components directly, otherwise they're not bound to these renderer props anywhere else than in our DefaultChildren component.

https://github.com/algolia/ui-components/blob/cf5586617855048d09cfe414ede458ddeace92aa/packages/react-recommendations/src/FrequentlyBoughtTogether.tsx#L40-L50

The same applies with Header and View.

Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! Is that what you had in mind? algolia/ui-components@fac42ac

packages/react-recommendations/src/ListView.tsx Outdated Show resolved Hide resolved
@shortcuts
Copy link
Member Author

shortcuts commented Jun 8, 2021

Closing this PR since we changed our implementation in #27 and #28

@shortcuts shortcuts closed this Jun 8, 2021
@shortcuts shortcuts deleted the feat/components branch June 8, 2021 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants