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

useState in react-native doesn't works on android via EXPO

$
0
0

I'm trying to make an user join a room in socket.io.The event sent from react-native client is :

export default function App() {  const [username, setUsername] = useState('')  const [room, setRoom] = useState('')  const [showChat, setShowChat] = useState(false)  const joinRoom = () => {    if (username === '' || room === '') return    socket.emit('join:room', {room: room, user: username, test: 'test'})    await setShowChat(true)  }

On web browser, it's working fine, and my node.js server receieve

{ room: '2894', user: '5656', test: 'test' }

But on my phone with explo, I correctly connect to web socket, but when I send the 'join:room' event, the server recieve this :

{ test: 'test', user: undefined }

For info, the useState() are updated when user change the TextInput:

<TextInput style={styles.input} placeholder='Room...' onChange={async (event) => {  await setRoom(event.target.value)}}/>

and the joinRoom() method is called when TouchableOpacity is pressed.

<TouchableOpacity onPress={joinRoom} style={styles.button}><Text style={styles.buttonText}> Join a room </Text></TouchableOpacity>

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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