错误消息 - TouchableOpacity 不是函数
Error message - TouchableOpacity is not a function
我是 React Native 的新手,现在正在开发我的第一个应用程序 :)
我收到此错误消息,提示“TouchableOpacity 不是函数”,请参阅此处的 screenshot。曾尝试Google理解但没有成功。
有人知道我的代码有什么问题吗?
import React from 'react'
import { useState } from 'react'
import { View, Vibration, TouchableOpacity } from 'react-native'
import styled from 'styled-components'
const TouchButton = styled.TouchableOpacity`
padding: 25px;
margin: 0px;
width: 250px;
borderRadius: 25px;
backgroundColor: #411271;
border: 4px #01AA31;
`;
const ButtonText = styled.Text`
textAlign: center;
fontSize: 20px;
justify-content: center;
alignItems: center;
color: #F5C603;
`;
const Title = styled.Text`
fontSize: 204px;
marginBottom: 50px;
color: #F5C603;
textAlign: center;
justifyContent: center;
alignItems: center;
`;
export const Training = ({activitiesArray}) => {
const [activity, setActivity] = useState("")
const getActivity = () => {
const theActivity = activitiesArray[Math.floor(Math.random() * activitiesArray.length)]
setActivity(theActivity.activity)
}
return (
<View>
<Title>
{activity}
</Title>
<TouchButton onPress={() => {
getActivity(); Vibration.vibrate()}}>
<ButtonText>Hur ska jag röra på mig idag?</ButtonText>
</TouchButton>
</View>
)
};
您似乎从错误的位置导入 styled-component
。您应该从 styled-components/native
导入。请参考官方文档:https://styled-components.com/docs/basics#react-native.
我是 React Native 的新手,现在正在开发我的第一个应用程序 :) 我收到此错误消息,提示“TouchableOpacity 不是函数”,请参阅此处的 screenshot。曾尝试Google理解但没有成功。
有人知道我的代码有什么问题吗?
import React from 'react'
import { useState } from 'react'
import { View, Vibration, TouchableOpacity } from 'react-native'
import styled from 'styled-components'
const TouchButton = styled.TouchableOpacity`
padding: 25px;
margin: 0px;
width: 250px;
borderRadius: 25px;
backgroundColor: #411271;
border: 4px #01AA31;
`;
const ButtonText = styled.Text`
textAlign: center;
fontSize: 20px;
justify-content: center;
alignItems: center;
color: #F5C603;
`;
const Title = styled.Text`
fontSize: 204px;
marginBottom: 50px;
color: #F5C603;
textAlign: center;
justifyContent: center;
alignItems: center;
`;
export const Training = ({activitiesArray}) => {
const [activity, setActivity] = useState("")
const getActivity = () => {
const theActivity = activitiesArray[Math.floor(Math.random() * activitiesArray.length)]
setActivity(theActivity.activity)
}
return (
<View>
<Title>
{activity}
</Title>
<TouchButton onPress={() => {
getActivity(); Vibration.vibrate()}}>
<ButtonText>Hur ska jag röra på mig idag?</ButtonText>
</TouchButton>
</View>
)
};
您似乎从错误的位置导入 styled-component
。您应该从 styled-components/native
导入。请参考官方文档:https://styled-components.com/docs/basics#react-native.