在handleClick函数中,更新这样的rootSiblings,
handleClick() { this.progressBar.update( <ProgressBar /> ); }
并在ProgressBar组件中,
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { View } from 'react-native';
const getFinishedWidth = progress => ({ width: progress * totalWidth });
const getUnfinishedWidth = progress => ({ width: (1 - progress) * totalWidth });
function CustomerReassignProgressBar(props) {
const { progress } = props;
return (
<View style={styles.bar}>
<View style={getFinishedWidth(progress)} />
<View style={getUnfinishedWidth(progress)} />
</View> );
}
CustomerReassignProgressBar.propTypes = { progress: PropTypes.number, };
const mapStateToProps = state => ({ progress: state.batchReassignProgress, });
export default connect(mapStateToProps)(ProgressBar);
然后,当调用handleClick()时,应用程序被粉碎,错误是,“找不到&#34;存储&#34;在&#34; Connect(ProgressBar)&#34;的上下文或道具中。将根组件包装在a中,或者显式传递&#34;存储&#34;作为&#34; Connect(ProgressBar)&#34;。&#39;
的道具如果我不在组件中使用connect,则效果很好。所以,我想,也许rootSiblings无法使用react-redux。但有谁知道这个问题?
答案 0 :(得分:0)
升级到react-native-root-siblings@4.x
然后
import { setSiblingWrapper } from 'react-native-root-siblings';
import { Provider } from 'react-redux';
const store = xxx;// get your redux store here
// call this before using any root-siblings related code
setSiblingWrapper(sibling => (
<Provider store={store}>{sibling}</Provider>
));