我需要用react native修复bug.问题出在哪里



错误:钩子调用无效。钩子只能在函数组件的主体内部调用。这可能是由于以下原因之一:

  1. React和渲染器的版本可能不匹配(例如React DOM(
  2. 你可能违反了胡克规则
  3. 同一应用程序中可能有多个React副本


import React, { PureComponent, useState } from 'react'
import { StoryContainer } from 'react-native-stories-view'
import {
TouchableOpacity,
Alert,
StyleSheet,
View,
Text,
SafeAreaView,
ImageBackground,
Image,
Platform,
StatusBar,
} from 'react-native'

import { connect } from 'react-redux'

class StoryViewScreen extends PureComponent {
constructor(props) {
super(props);
this.state = {

}
}

render() {
const { files } = this.props.route.params;
const fileUrls = [];
for (var i = 0; i < files.length; i++) {
fileUrls.push(files[i].uri);
}
console.log("files path:", fileUrls);
return (
<View style={{ flex: 1, flexDirection: 'column' }}>
{Platform.OS === 'ios' && (
<View style={{
backgroundColor: 'gray',
height: 45,
}}>
<StatusBar barStyle="light-content" backgroundColor={'green'} />
</View>
)}
{Platform.OS === 'android' && (
<StatusBar barStyle="dark-content" backgroundColor={'white'} />
)}

<SafeAreaView style={{ flex: 1, flexDirection: 'column', backgroundColor: 'gray' }}>
<StoryContainer
visible={true}
enableProgress={false}
images={fileUrls}
duration={5}
containerStyle={{
width: '100%',
height: '100%',
}} />
{/* <Text>This is teh realdksfjdsklfj</Text> */}
</SafeAreaView>
</View>
);
}
};

const style = StyleSheet.create({

});

function mapStateToProps(state) {
return {
// currentUser: state.user.currentUser,
};
}

function mapDispatchToProps(dispatch) {
return {
dispatch
};
}

export default connect(mapStateToProps, mapDispatchToProps)(StoryViewScreen);

不能在类组件中使用useState,而是使用setState来设置状态。

最新更新