作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试向 React Native 中的功能组件添加引用,以便在 FlatList 组件上使用scrollToEnd。
我想为此使用 recompose,正如他们的文档所述, toClass() 应该能够处理这个问题。但是,没有给出示例。
目前,这是我失败的实现。有人可以告诉我我做错了什么吗?
我将不胜感激!
import React from 'react';
import PropTypes from 'prop-types';
import { FlatList, View, Text } from 'react-native';
import { graphql } from 'react-apollo';
import { compose, toClass, lifecycle } from 'recompose';
import CommentItem from './CommentItem';
import { commentsQuery } from '../../queries/comments';
const CommentScreen = ({ onRef, currentUser, data: { comments, loading } }) => {
if (loading) {
return (
<View>
<Text>Loading...</Text>
</View>
);
}
return (
<FlatList
ref={ref => {
this.refs.commentList = ref;
}}
data={comments}
keyExtractor={item => item.id}
renderItem={({ item }) => <CommentItem {...item} currentUser={currentUser} />}
/>
);
};
export default compose(
toClass,
graphql(commentsQuery),
lifecycle({
componentDidMount() {
console.log('PROPZZZ', this.commentList);
},
}),
)(CommentScreen);
CommentScreen.propTypes = {
fetchComments: PropTypes.func.isRequired,
updateId: PropTypes.number.isRequired,
comments: PropTypes.arrayOf(Object),
text: PropTypes.string.isRequired,
};
最佳答案
如果需要使用ref
,只需使用类组件而不是函数组件。但是,如果由于某些原因需要使用功能组件,则可以使用 withHandlers
。使用方法请参见this SO question的回答。
关于reactjs - 如何使用 recompose 的 toClass HOC 向功能组件添加引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46572721/
我通过 Javassist 修改我的 TestClass 的 getMessage() 方法体,如下所示: ClassPool cp = new ClassPool(true); CtClass ct
创建动态类的步骤如下: try { classLoader = Class.forName("org.yaddayadda.DynamicClass"
我正在尝试向 React Native 中的功能组件添加引用,以便在 FlatList 组件上使用scrollToEnd。 我想为此使用 recompose,正如他们的文档所述, toClass()
我是一名优秀的程序员,十分优秀!