I am attempting to have a user join a room in socket.io. The event sent from my react-native client looks like this:
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)
}
When using the web browser, everything works as expected and my node.js server receives:
{ room: '2894', user: '5656', test: 'test' }
However, when I try on my phone with Expo, although I can connect to the web socket correctly, the server ends up receiving this:
{ test: 'test', user: undefined }
Just for reference, the useState() functions are updated whenever the user changes the TextInput value:
<TextInput
style={styles.input}
placeholder='Room...'
onChange={async (event) => {
await setRoom(event.target.value)
}}/>
The joinRoom() method is triggered when the TouchableOpacity component is pressed.
<TouchableOpacity onPress={joinRoom} style={styles.button}>
<Text style={styles.buttonText}> Join a room </Text>
</TouchableOpacity>