Skip to content

Commit

Permalink
fixes #1428 - fixed the compatibility layer. I assume now Tagify only…
Browse files Browse the repository at this point in the history
… supports React v17 and above
  • Loading branch information
yairEO committed Dec 21, 2024
1 parent 2d8abd2 commit 108c6bc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
22 changes: 1 addition & 21 deletions src/react-compat-layer.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
let React;
let memo;
let useMemo;
let useEffect;
let useRef;
let useCallback;

async function initReact() {
try {
// Try to import React as a namespace (React 18+)
const ReactModule = await import('react');
React = ReactModule.default || ReactModule;
({ memo, useMemo, useEffect, useRef, useCallback } = ReactModule);
} catch (e) {
console.error('Failed to import React:', e);
}
}

initReact();

function renderToStaticMarkup(element) {
if (typeof element === 'string') {
return element;
Expand Down Expand Up @@ -51,4 +31,4 @@ function renderToStaticMarkup(element) {
return '';
}

export { React as default, memo, useMemo, useEffect, useRef, useCallback, renderToStaticMarkup };
export { renderToStaticMarkup };
3 changes: 2 additions & 1 deletion src/react.tagify.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import React, {memo, useMemo, useEffect, useRef, useCallback, renderToStaticMarkup} from './react-compat-layer'
import {memo, useMemo, useEffect, useRef, useCallback} from 'react';
import {renderToStaticMarkup} from './react-compat-layer'
// import {renderToStaticMarkup} from "react-dom/server"
// import {string, array, func, bool, object, oneOfType} from "prop-types"
import Tagify from "./tagify.js"
Expand Down

0 comments on commit 108c6bc

Please sign in to comment.