From 5864f5cc3d5d9b972455a9fcd449463eed303727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aykut=20Sara=C3=A7?= Date: Thu, 28 Sep 2023 17:35:53 +0300 Subject: [PATCH] fix(react): add export default --- scripts/generate-react-exports.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/generate-react-exports.js b/scripts/generate-react-exports.js index a2f56ccb..6b0b6d3c 100644 --- a/scripts/generate-react-exports.js +++ b/scripts/generate-react-exports.js @@ -27,12 +27,14 @@ for (const module of customElementsModules) { const componentDeclaration = declarations.find(declaration => declaration.customElement === true); const { events, name: componentName, tagName: fileName, jsDoc } = componentDeclaration; - const eventNames = events?.reduce((acc, curr) => { + const eventNames = + events?.reduce((acc, curr) => { acc[getReactEventName(curr.name)] = curr.name; return acc; }, {}) || {}; - const eventTypes = events?.map(event => { + const eventTypes = + events?.map(event => { const eventName = getReactEventName(event.name); const eventType = cleanGenericTypes(componentDeclaration.typeParameters, event.type.text); const predefinedEventName = `${componentName}${eventName.split("onBl")[1]}`; @@ -52,13 +54,15 @@ for (const module of customElementsModules) { const source = ` ${jsDoc} export const ${componentName}: React.LazyExoticComponent> = - React.lazy(() => customElements.whenDefined('${fileName}').then(() => - createComponent<${componentType}>({ - react: React, - displayName: "${componentName}", - tagName: "${fileName}", - elementClass: customElements.get("${fileName}"), - events: ${JSON.stringify(eventNames)}, + React.lazy(() => + customElements.whenDefined('${fileName}').then(() => ({ + default: createComponent<${componentType}>({ + react: React, + displayName: "${componentName}", + tagName: "${fileName}", + elementClass: customElements.get("${fileName}"), + events: ${JSON.stringify(eventNames)}, + }) })) ); `;