Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

React Native: How to pass a props variable from other js file to app.js file

$
0
0

I am a new to react native programming.

Following is the code I am following:

App.js Code:

export default function App() {  const [userNumber, setUserNumber] = useState();  const startGameHandler = (selectedNumber) => {    setUserNumber(selectedNumber);  };  let content =  <StartGameScreen onStartGame={userNumber} />;  if(userNumber){     content = <GameScreen userChoice = {startGameHandler}/>  }

other js file:

let confirmedOutput;    if (confirmed) {        confirmedOutput = (<Card style = {styles.summaryContainer}><Text>You Selected</Text><NumberContainer>{selectedNumber}</NumberContainer><Button title= "Start Game" color = {colors.primary} onPress = {() => props.onStartGame(selectedNumber)}/></Card>        );    };

I want to transfer selectedNumber from other js file to App.js file but I am getting error as props.onStartGame is not a fuction.

Help me solve the error.


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>