-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
renderProps无法按照文档上的使用方式进行 #4180
Comments
欢迎提交 Issue~ 如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏 如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。 Good luck and happy coding~ |
CC @yuche |
根据 #4150 上的讨论,发现通过 所以现在剩下的问题是: |
@yuche 测试了一下, function handleGetUserInfo(resp) {
console.log(resp);
}
Taro.eventCenter.on("renderPageRsMpc", e => {
if (!Taro.shallowEqual(e, this.renderPageRsMpc)) {
this.renderPageRsMpc = e;
this.setState({});
}
});
const renderPageRsMpc = () => {
return <View className="index">
<Text>Hello world!</Text>
<Button openType="getUserInfo" onGetUserInfo={handleGetUserInfo}>
获取用户信息
</Button>
</View>;
};
return <Page renderPage={<View>{renderPageRsMpc(this.renderPageRsMpc)}</View>} />; |
不太明白这么编译的理由。。。WEB端应该是最直接的,直接传方法就行 |
@yuche 有官方的交流渠道么,gitter,群啥的,因为公司重度使用Taro,目前正在项目开发,这一波完了之后会考虑贡献一下代码,希望能有一个快速交流的渠道 |
交流群 在上面有嘛,#198 |
@yuche 修复了吗?有发版么? |
晚点 |
@yuche 老哥,今天发版本么 |
@yuche 更新到1.3.14还是不行啊,WEB端编译没变,还是之前的。 render() {
function handleGetUserInfo(resp) {
console.log(resp);
}
Taro.eventCenter.on("renderPagenQmQL", e => {
if (!Taro.shallowEqual(e, this.renderPagenQmQL)) {
this.renderPagenQmQL = e;
this.setState({});
}
});
const renderPagenQmQL = () => {
return <View className="index">
<Text>Hello world!</Text>
<Button openType="getUserInfo" onGetUserInfo={handleGetUserInfo}>
获取用户信息
</Button>
</View>;
};
return <Page renderPage={<View>{renderPagenQmQL(this.renderPagenQmQL)}</View>} />;
}
// page.js
export default class Page extends Taro.Component {
render() {
const props = this.props;
return <View>{props.renderPage()}</View>;
}
} 源码如下: // page.js
import { View } from '@tarojs/components'
export default function Page(props) {
return <View>{props.renderPage()}</View>
}
// 调用
return (
<Page
renderPage={() => {
return (
<View className='index'>
<Text>Hello world!</Text>
<Button openType='getUserInfo' onGetUserInfo={handleGetUserInfo}>
获取用户信息
</Button>
</View>
)
}}
/>
) |
不好意思, |
这个 ESLint(taro/render-props) 错误:无法操作 this.props.renderRefresh
-----
464 | ></Map>
465 |
> 466 | { this.props.renderRefresh(11111) } 环境:
|
在2.2.15中依然不支持 |
问题描述
renderProps无法按照文档上说的使用方法进行调用,只能静态渲染
复现步骤
组件代码:
编译之后的axml
会在
_createData
里面调用renderPage
但是如果使用
{this.renderPage}
却可以正常运行,这一点跟文档不符。https://nervjs.github.io/taro/docs/render-props.html
期望行为
可以对
renderPage
进行传参根据 #4150 上的讨论,发现通过
{ renderPage }
在参数上结构然后调用是可以的。所以现在剩下的问题是:
props.renderPage()
不行,以及无法传递匿名变量,比如renderPage('abc')
,最终拿到的是undefined
系统信息
The text was updated successfully, but these errors were encountered: