我正在使用React的钩子,我想拥有一个从数据库中检索到的值作为初始值。但是,出现以下错误:
不变违规:不变违规:渲染的钩子比 在上一个渲染期间。
ExternalContext econtext = FacesContext.getCurrentInstance().getExternalContext();
econtext.responseReset();
econtext.setResponseContentType(contentType);
econtext.setResponseHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
econtext.setResponseContentLength(contentLength);
我正在使用React Apollo钩子。
更新
const { data, loading, error } = useQuery(GET_DATA)
const { initialValue } = data
const [value, setValue] = useState(initialValue)
答案 0 :(得分:1)
问题是您正在使用return下面的钩子。尝试更新
export default NotificationScreen = ({ navigation }) => {
const { data: initialNotificationSettings, loading: loadingInitialSettings, error: initialSettingsError } = useQuery(GET_NOTIFICATION_SETTINGS)
const [borrowerPending, notifyBorrowerPending] = useState("")
useEffect(() => {
if (initialNotificationSettings.me) {
const { borrowerLendingNotificationToken } = initialNotificationSettings.me
notifyBorrowerPending(borrowerLendingNotificationToken);
}
}, [initialNotificationSettings]);
if (loadingInitialSettings) {
return (
<View style={[styles.container, styles.horizontal]}>
<ActivityIndicator size="large" color="#FF5D4E" />
</View>
)
}
if (initialSettingsError) return <Text>Error...</Text>
return (
<SafeAreaView style={styles.container}>
</SafeAreaView>
)
}