/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ import React, {useState, useEffect} from 'react'; // $FlowFixMe 'react-native' won't resolve here, as this file is just an example.. import {StyleSheet, View, Text, Button} from 'react-native'; import {addPlugin} from 'react-native-flipper'; export default function FlipperTicTacToe() { const [status, setStatus] = useState('Waiting for Flipper Desktop Player...'); const [gameState, setGameState] = useState({ cells: [], turn: ' ', winner: ' ', }); const [connection, setConnection] = useState(null); useEffect(() => { addPlugin({ getId() { return 'ReactNativeTicTacToe'; }, onConnect(connection) { setStatus('Desktop player present'); setConnection(connection); // listen to updates connection.receive('SetState', (gameState, responder) => { if (gameState.winner !== ' ') { setStatus( `Winner is ${gameState.winner}! Waiting for a new game...`, ); } else { setStatus( gameState.turn === 'X' ? 'Your turn...' : 'Awaiting desktop players turn...', ); } setGameState(gameState); responder.success(); }); // request initial state connection.send('GetState'); }, onDisconnect() { setConnection(null); setStatus('Desktop player gone...'); }, }); }, []); return ( Flipper Tic-Tac-Toe {status} {gameState.cells.map((state, idx) => (