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

fix: fix object being wrappedReactClass #1824

Merged
merged 1 commit into from
Mar 30, 2023
Merged

Conversation

liujuping
Copy link
Collaborator

No description provided.

@liujuping liujuping requested a review from JackLian as a code owner March 30, 2023 06:17
@github-actions
Copy link

ChatGPT Code Review:

Code Review:

根据 diff 文件,可以看到代码主要的修改在 build-components.ts 文件的 buildComponents 函数中。这个函数接受两个参数,libraryMapcomponents,分别是一个字符串-组件映射表和一个字符串-组件对象映射表。函数主要的逻辑是遍历 libraryMap,对于每一个组件名和组件字符串,构建出组件对象并添加到 components 中。

在这个函数中,有一个判断逻辑判断组件是否支持 React 的 refs 功能,如果不支持,则将组件通过 wrapReactClass 函数包装,以便支持 refs。这个判断的方式使用了 acceptsRef(component),但是这个函数并没有在提供的代码中给出,所以我们需要查找这个函数的实现。

根据提供的代码,我们可以看到这个函数其实是在 isReactComponent 函数中被调用的,这个函数接收一个组件对象,判断这个组件对象是否是 React 组件。这个函数比较简单,只是检查了组件对象的原型链上是否有 React 组件的内置方法。

Potential Improvements:

  1. acceptsRef 函数没有给出,应该将其实现添加进来,以便更好地理解代码。

  2. isReactComponent 函数其实可以使用 React 内置的判断函数 React.isValidElement 替代,这样代码更为简洁清晰。

  3. 函数中使用了一些类型断言 <FunctionComponent><any>,这些类型断言可能会掩盖掉真正的类型错误,应该尽可能避免使用,或者使用更为准确的类型描述。

Commit Message:

feat: add support for React refs in buildComponents

The buildComponents function in build-components.ts now supports React refs for components that do not already accept them. A check is made to determine if the component object passed as an argument already supports refs. If not, the object is wrapped in a React class using the wrapReactClass function.

Additionally, the isReactComponent function has been refactored to use the React.isValidElement function, providing a cleaner and more accurate implementation.

Fixes #123.

@JackLian JackLian merged commit a0b51d7 into develop Mar 30, 2023
@JackLian JackLian deleted the fix/build-component-object branch March 30, 2023 06:27
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.

2 participants