Home > Enterprise >  How to export data from files react-native
How to export data from files react-native

Time:12-04

I have a few files like Train.js and Result.js. How can i make export voiceData from Train.js to Result.js? Files bellow:

Train.js

const Train = () => {
  const [user] = useAuth()
  let [started, setStarted] = useState(false);
  let [results, setResults] = useState([]);
  const [voiceData, setVoiceData] = useState([]);
  
  const navigation = useNavigation()
  const toResult = () => {
    navigation.navigate('Result')

}

Result.js:

return (
    <View style={styles.container}>
      <Text>{voiceData}</Text>
      <View>

CodePudding user response:

Depends on how you are using it and what you want to do with it but here's an example of exporting and importing.

// Train.js
export default Train = () => {
  const voiceData = "hesdsdsdsdllo";
  return voiceData;
}
// App.js
import React from 'react';
import Train from './Train.js';

export function App(props) {
  return (
    <div className='App'>
      <h1>Hello React. {Train()}</h1>
    </div>
  );
}

Train is a function so return what you need from it.

  • Related