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

Change game without changing the games added before

$
0
0

Im consuming a json file with the some games.I want to add a new Game and the chooseGameToAdd() choose what game will be without changing the games added before

enter image description hereenter image description here

Json file:

enter image description here

Code:

import { games as gamesJson } from './games.json';const App: React.FC = () => {  const [whichGameIsVar, setWhichGameIsVar] = useState(0);  const [state, setState]: any = useState([]);  let game = gamesJson[whichGameIsVar].game;  function addGame() {    setState([...state, game]);  }  function chooseGameToAdd() {    setWhichGameIsVar(whichGameIsVar + 1);  }  const GamesParent = (props: any) => {    return (<div color={game}><div>{game}</div></div>    );  };  return (<div>      {state.map((item: any) => (<GamesParent key={item.id}>{item}</GamesParent>      ))}<button onClick={addGame}>Add a Game</button><button onClick={chooseGameToAdd}>Choose Game To Add</button></div>  );};export default App;

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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