Reputation: 81
i am trying to use uuidv4 its show a error
first iam install uuid using this command npm i uuidv4
after i am import {v4} from 'uuid'; to app.js
This is my error
TypeError: (0,_uuid.uuid) is not a function. (in'(0,_uuid.uuid)()','(0,_uuid.uuid)' is undefined)
this is my code
import React, {useState} from 'react';
import {View, Text, StyleSheet, FlatList} from 'react-native';
import Header from './components/Header';
import {uuid} from 'uuid';
const App = () => {
const [items, setItems] = useState([
{
id: uuid(),
text: 'Milk',
},
]);
return (
<View style={styles.container}>
<Header />
<FlatList
data={items}
renderItem={({item}) => <Text>{item.text}</Text>}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default App;
Upvotes: 7
Views: 6540
Reputation: 37318
You have to use uuid
package and react-native-get-random-values
before the uuid
import. uuid
package has a V4 implementation.
Check the documentation under UUID > React Native:
React Native
- Install
react-native-get-random-values
- Import it before
uuid
:import 'react-native-get-random-values'; import { v4 as uuidv4 } from 'uuid';
Upvotes: 16