Closed mkilpatrick closed 9 months ago
Start a new pull request in StackBlitz Codeflow.
You can try using it in the following way.
import R from '@material-tailwind/react';
export async function render() {
const foo = (
<>
<R.Collapse open>
<div>HII</div>
</R.Collapse>
</>
);
return ReactDOMServer.renderToString(foo);
}
That doesn't work, at least for react-slick. ReferenceError: Slider is not defined
this could be a problem and this solution is not universal at the same time.
For @material-tailwind/react
, the way @XiSenao said is the correct way.
For react-slick
, you'll need to access it by
import SlickDefault from 'react-slick'
const Slick = SlickDefault.default
This is because react-slick
exports it by
"use strict";
var _slider = _interopRequireDefault(require("./slider"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
exports["default"] = _slider["default"];
Closing as this is not a bug in Vite.
Describe the bug
I'm not sure if this is a Vite error specifically, but I've been seeing the same error arise from some CJS libs. This occurs in SSR mode.
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
It occurs from react-slick - https://github.com/akiran/react-slick/issues/2206 and @material-tailwind-react -https://github.com/creativetimofficial/material-tailwind/issues/558
You can get around the issue by dynamically importing the library to only run client-side, but that's not an optimal solution.
Reproduction
https://stackblitz.com/edit/vitejs-vite-bs4gbs?file=server.js
Steps to reproduce
No response
System Info
Used Package Manager
npm
Logs
No response
Validations