<View>
<View><SomeComponent/></View>
<Text>
<Text>Hello World!</Text>
<TextInput>
<TextInput defaultValue="Enter what you want to display before the user enters any data"></TextInput>
<Image>
<Image source={{uri:'enter your image uri here'}}/>
<ScrollView>
<ScrollView><SomeComponent/></ScrollView>
const [something,setSomething] = useState(initialState);
. This code sets and initial state and returns a function element setSomething and current state value something.setSomething(nextState)
function, returned by the useState hook, is used to update the state of a component. However, calling this function doesn't immediately change the state in the current code. Instead, it schedules the state update to happen during the next execution of the component.export default function Counter() {
const [count, setCount] = useState(0);
function handleClick() {
setCount(count + 1);
}
}
The setup function runs the first time your component shows on the page.
Whenever the values in the dependencies list change, React will:
Run a cleanup function (if you return one in setup) to handle old data.
Then, run the setup function again with the new data.
You can only use useEffect at the top level of your component, not inside loops or if statements.
const [serverUrl, setServerUrl] = useState('https://localhost:1234');
useEffect(() => { //setup function
const connection = createConnection(serverUrl, roomId);
connection.connect();
return () => { //this is the clean up function
connection.disconnect();
};
}, [roomId, serverUrl]); // [roomId,serverUrl] are the dependencies