ReactFix
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • React
  • React Native
  • Programming
  • Object Oriented Programming

Wednesday, December 14, 2022

[FIXED] How to export data from files react-native

 December 14, 2022     react-native   

Issue

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>


Solution

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.



Answered By - mcool
Answer Checked By - - David Marino (ReactFix Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Post Older Post Home

Featured Post

Is Learning React Difficult?

React is difficult to learn, no ifs and buts. React isn't inherently difficult to learn. It's a framework that's different from ...

Total Pageviews

Copyright © ReactFix