Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

createNativeComponent 现在的实现容易因为没有 ref 报 warning #478

Closed
LeoYuan opened this issue Dec 12, 2019 · 3 comments · Fixed by #486
Closed

createNativeComponent 现在的实现容易因为没有 ref 报 warning #478

LeoYuan opened this issue Dec 12, 2019 · 3 comments · Fixed by #486

Comments

@LeoYuan
Copy link
Contributor

LeoYuan commented Dec 12, 2019

bug 描述

remax 对原生小程序组件会通过 React.forwardRef 进行一层封装,其中会通过 props.__ref 往原生组件「传递」ref,在生成的 axml 中,也会通过类似 <form-0 ref="{{item.props['__ref']}}"> 获取 ref~

此时有个断言是,用户在使用小程序封装的组件时一定会传入 ref,但很可能没传,从而导致截图中的 warning,建议可以在用户没有传 ref 的时候,mock 一个实现,如:props.__ref = () => {}

复现步骤
使用任意一个自定义组件即可复现

期望结果
没有 warning

复现代码
😁

版本信息:

  • remax 版本: [e.g. 1.0.0]
  • 手机型号 [e.g. iPhone X]
  • 小程序端 [e.g. 微信小程序]
  • 小程序版本[e.g. 2.3.0]
  • 开发环境 [e.g. mac OS]

其他信息

image

@LeoYuan LeoYuan added the bug Something isn't working label Dec 12, 2019
@Darmody Darmody added improvement and removed bug Something isn't working labels Dec 12, 2019
@Darmody
Copy link
Contributor

Darmody commented Dec 12, 2019

复现代码是怎么样的

@LeoYuan
Copy link
Contributor Author

LeoYuan commented Dec 12, 2019

随便引用一个自定义组件就能复现~

import Badge from 'mini-antui/es/badge';

<View>
  <Badge><View slot="inner">Remax</View></Badge>
</View>

根因就是 axml 如 <form-0 ref={{item.props.__ref}} /> 中的 item.props.__ref 出现了 undefined,就会出现这个 warning~

@Darmody
Copy link
Contributor

Darmody commented Dec 15, 2019

我试了下没有警告额

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants