如何在 Qwik 中使用 React 组件?

huangapple go评论95阅读模式
英文:

How to use React components in Qwik?

问题

可以在 Qwik 框架中使用 React 组件库中的 React 组件吗?我正在尝试使用我已安装的依赖项中的组件,但它们是用 React 编写的。

英文:

Is it possible to use React components from a component library in Qwik framework?

I'm trying to use components from a dependency that i have installed but they are written in React.

答案1

得分: 1

In short: you can but should avoid it if you can and only should use it as a migration strategy. For more information: Use qwikify$() as a migration strategy

QwikReact allows you to use React components in Qwik, including the whole ecosystem of component libraries.

You need to install:

npm run qwik add react

The qwikify the component you want to use:

/** @jsxImportSource react */

import { qwikify$ } from '@builder.io/qwik-react';
import { ReactComponent } from '@react/component/library';

export const Component = qwikify$(ReactComponent);

> Important: You need to import /** @jsxImportSource react */ at the top
> of your file, this is an instruction to the compiler to use React as
> the JSX factory.

For more information see Qwik React.

英文:

In short: you can but should avoid it if you can and only should use it as a migration strategy. For more information: Use qwikify$() as a migration strategy

QwikReact allows you to use React components in Qwik, including the whole ecosystem of component libraries.

You need to install:

npm run qwik add react

The qwikify the component you want to use:

/** @jsxImportSource react */

import { qwikify$ } from '@builder.io/qwik-react';
import { ReactComponent } from '@react/component/library';

export const Component = qwikify$(ReactComponent);

> Important: You need to import /** @jsxImportSource react */ at the top
> of your file, this is an instruction to the compiler to use React as
> the JSX factory.

For more information see Qwik React.

huangapple
  • 本文由 发表于 2023年3月9日 21:33:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75685318.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定