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

1.3.11版本h5不能正常使用render开头的属性 #4021

Closed
stcer opened this issue Jul 31, 2019 · 6 comments
Closed

1.3.11版本h5不能正常使用render开头的属性 #4021

stcer opened this issue Jul 31, 2019 · 6 comments
Assignees

Comments

@stcer
Copy link

stcer commented Jul 31, 2019

问题描述
在h5下父组件传递以render开头的属性值为函数, 在子组件不能使用, 属性不以render开头运行正常

复现步骤

# index.js
import { View} from '@tarojs/components'
import MouseA from  './MouseA'

export default function IndexPage() {
  return (
    <View>
      <MouseA renderCat={() => (
        <View>MouseA 3</View>
      )}
      />
    </View>
  )
}

# MouseA.jsx
import {View} from "@tarojs/components";
import PropTypes from "prop-types";

function MouseA({renderCat}) {
  return (
    <View>
      {renderCat()}
    </View>
  )
}

MouseA.propTypes = {
  renderCat: PropTypes.func,
};

export default MouseA

期望行为
正常运行

报错信息

TypeError: renderCat is not a function
    at MouseA.render (MouseA.js?946e:11)
    at eval (index.esm.js?eb37:1761)
    at errorCatcher (index.esm.js?eb37:1655)
    at renderComponent (index.esm.js?eb37:1760)
    at mountComponent (index.esm.js?eb37:1733)
    at ComponentWrapper.init (index.esm.js?eb37:2137)
    at createElement (index.esm.js?eb37:1398)
    at mountChild (index.esm.js?eb37:1463)
    at mountVNode$1 (index.esm.js?eb37:1453)
    at createElement (index.esm.js?eb37:1403)

(anonymous) | @ | index.esm.js?eb04:2473
-- | -- | --
  | Promise.catch (async) |   |  
  | updateComponent | @ | index.esm.js?eb04:2472
  | componentDidMount | @ | index.esm.js?eb04:2481
  | (anonymous) | @ | index.esm.js?eb37:1779
  | errorCatcher | @ | index.esm.js?eb37:1655
  | (anonymous) | @ | index.esm.js?eb37:1778
  | flushMount | @ | index.esm.js?eb37:1774
  | updateComponent | @ | index.esm.js?eb37:1868
  | rerender | @ | index.esm.js?eb37:1938
  | Promise.then (async) |   |  
  | nextTick | @ | index.esm.js?eb37:73
  | enqueueRender | @ | index.esm.js?eb37:1926
  | setState | @ | index.esm.js?eb37:1966
  | push | @ | index.esm.js?eb04:2645
  | componentDidMount | @ | index.esm.js?eb04:2719
  | (anonymous) | @ | index.esm.js?eb37:1779
  | errorCatcher | @ | index.esm.js?eb37:1655
  | (anonymous) | @ | index.esm.js?eb37:1778
  | flushMount | @ | index.esm.js?eb37:1774
  | render | @ | index.esm.js?eb37:2057
  | (anonymous) | @ | app.js?d0a8:74
  | ./.temp/app.js | @ | app.js:915
  | __webpack_require__ | @ | app.js:767
  | fn | @ | app.js:130
  | 0 | @ | app.js:2166
  | __webpack_require__ | @ | app.js:767
  | (anonymous) | @ | app.js:902
  | (anonymous) | @ | app.js:905

系统信息

  Taro CLI 1.3.11 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 10.16.0 - G:\Programs\nodejs\node.EXE
      Yarn: 1.17.3 - G:\Programs\nodejs\yarn.CMD
      npm: 6.9.0 - G:\Programs\nodejs\npm.CMD
@taro-bot
Copy link

taro-bot bot commented Jul 31, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@calimanco
Copy link

之前的版本可以的吗?
记得一直都不可以这样写的,render不能继承也不能改名,据说是小程序的限制。

@stcer
Copy link
Author

stcer commented Jul 31, 2019

之前的版本不清楚, 小程序是支持这种写法的, 只是h5下不正常

@yuche yuche self-assigned this Jul 31, 2019
@shenghanqin
Copy link
Collaborator

之前的版本不清楚, 小程序是支持这种写法的, 只是h5下不正常

为啥要用renderCat这样的命名呢?
onClick表示事件
renderList表示jsx的视图
属性开头一般是is,show,list等,不建议用render开头,会造成一定的混淆

@stcer
Copy link
Author

stcer commented Aug 1, 2019

有些场景下是有用的, 虽然也可以通过hook或别的方式实现
http://taro-docs.jd.com/taro/docs/render-props.html

@yuche yuche removed their assignment Aug 1, 2019
@yuche yuche added the H5 label Aug 1, 2019
@taro-bot
Copy link

taro-bot bot commented Aug 1, 2019

CC @Littly

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

No branches or pull requests

5 participants