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

cloneElement in app.js occurs error #12518

Closed
edwardfxiao opened this issue Sep 19, 2022 · 1 comment
Closed

cloneElement in app.js occurs error #12518

edwardfxiao opened this issue Sep 19, 2022 · 1 comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@edwardfxiao
Copy link

相关平台

微信小程序

小程序基础库: 2.26.0
使用框架: React

复现步骤

app.js: return <View>{props.children}</View> -> return <View>{cloneElement(props.children)}</View>;

OR

app.js: return this.props.children -> return cloneElement(this.props.children)

期望结果

No error and renders the children.

实际结果

Error: Minified React error ...
image

环境信息

👽 Taro v3.5.5


  Taro CLI 3.5.5 environment info:
    System:
      OS: macOS 12.0.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
      Yarn: 1.22.18 - ~/.nvm/versions/node/v16.13.0/bin/yarn
      npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
    npmPackages:
      @tarojs/cli: 3.5.5 => 3.5.5
      @tarojs/components: 3.5.5 => 3.5.5
      @tarojs/helper: 3.5.5 => 3.5.5
      @tarojs/plugin-framework-react: 3.5.5 => 3.5.5
      @tarojs/plugin-platform-alipay: 3.5.5 => 3.5.5
      @tarojs/plugin-platform-jd: 3.5.5 => 3.5.5
      @tarojs/plugin-platform-qq: 3.5.5 => 3.5.5
      @tarojs/plugin-platform-swan: 3.5.5 => 3.5.5
      @tarojs/plugin-platform-tt: 3.5.5 => 3.5.5
      @tarojs/plugin-platform-weapp: 3.5.5 => 3.5.5
      @tarojs/react: 3.5.5 => 3.5.5
      @tarojs/router: 3.5.5 => 3.5.5
      @tarojs/runtime: 3.5.5 => 3.5.5
      @tarojs/shared: 3.5.5 => 3.5.5
      @tarojs/taro: 3.5.5 => 3.5.5
      @tarojs/taro-h5: 3.5.5 => 3.5.5
      @tarojs/webpack5-runner: 3.5.5 => 3.5.5
      babel-preset-taro: 3.5.5 => 3.5.5
      eslint-config-taro: 3.5.5 => 3.5.5
      react: ^18.0.0 => 18.2.0

If this is not technically an issue, then I am sorry to open it here.

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Sep 19, 2022
@Chen-jj
Copy link
Contributor

Chen-jj commented Sep 19, 2022

@edwardfxiao Because this.props.children here will be an Array.So you can't clone it.

Maybe you could try:

this.props.children.map(item => React.cloneElement(item))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants