cant find variable document on React Native
See original GitHub issueHey,
Iam trying to use this library inside react-native, however I keep getting
Can't find variable: Document
I have this notifcation component:
import { MaterialIcons } from '@expo/vector-icons'
import React, { useRef } from 'react'
import { useToaster } from 'react-hot-toast'
import { Animated, Text, View } from 'react-native'
const Toast = ({ t, updateHeight, offset }) => {
const fadeAnim = useRef(new Animated.Value(0.5)).current // Initial value for opacity: 0
const posAnim = useRef(new Animated.Value(-80)).current // Initial value for opacity: 0
React.useEffect(() => {
Animated.timing(fadeAnim, {
toValue: t.visible ? 1 : 0,
duration: 300,
useNativeDriver: true,
}).start()
}, [fadeAnim, t.visible])
React.useEffect(() => {
Animated.spring(posAnim, {
toValue: t.visible ? offset : -80,
useNativeDriver: true,
}).start()
}, [posAnim, offset, t.visible])
return (
<Animated.View
pointerEvents='none'
style={{
position: 'absolute',
left: 0,
right: 0,
zIndex: 9999,
alignItems: 'center',
opacity: fadeAnim,
transform: [
{
translateY: posAnim,
},
],
}}>
<View
onLayout={(event) =>
updateHeight(t.id, event.nativeEvent.layout.height)
}
style={{
marginTop: 50,
backgroundColor: t.type === 'success' ? '#4caf50' : '#f44336',
maxWidth: '80%',
borderRadius: 30,
flexDirection: 'row',
alignItems: 'center',
paddingVertical: 8,
paddingHorizontal: 12,
}}
key={t.id}>
<MaterialIcons
name={t.type === 'success' ? 'check-circle-outline' : 'error-outline'}
size={24}
color='white'
/>
<Text
style={{
color: '#fff',
padding: 4,
flex: 1,
textAlign: 'center',
}}>
{t.message}
</Text>
</View>
</Animated.View>
)
}
const Notification = () => {
const { toasts, handlers } = useToaster()
return (
<View
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
}}>
{toasts.map((t) => (
<Toast
key={t.id}
t={t}
updateHeight={handlers.updateHeight}
offset={handlers.calculateOffset(t.id, {
reverseOrder: false,
})}
/>
))}
</View>
)
}
export default Notification
and I use that instead of <Toaster />
Apart from that the only imports I do look like this:
import { toast } from 'react-hot-toast'
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (3 by maintainers)
Top Results From Across the Web
android - Can't find variable: document - Stack Overflow
When running in the context of a browser, the document element is available by default. In React Native, however, the set of elements...
Read more >React-Native: "Can't find variable: document" #6910 - GitHub
Getting "Can't find variable: document" error when launching React-Native app with storybook. This is only coming when i am including this line ...
Read more >Render Error Can't find variable View Can't find ... - YouTube
Render Error Can't find variable View Can't find variable Text Can't find StyleSheet React Native. Watch later. Share. Copy link.
Read more >React Native and Apollo: Can't find variable - appsloveworld
Coding example for the question React Native and Apollo: Can't find variable: document-React Native.
Read more >A Crime in React Nativeland —The Villain Among Us - Enki Blog
The story of the Nightmare on Content Street in React Native started of with a parsing error for a ... can't find variable...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 for any progress on this?
Workaround:
change
import { useToaster } from 'react-hot-toast'
toimport { useToaster } from 'react-hot-toast/src/core/use-toaster'
and when creating a toast use: