How to use Model/State in TextInput in React Native #1894
-
I'm a classic React Native programmer, I usually create my projects with After cloning the boilerplate and compiling successfully 😊, I run the command
After that I added it to the
And finally in my screen I have simple experiment 😷:
But this is where my doubt is 😢, first it doesn't let me write in the text field (It cannot be edited, I write and it returns the same value 😞), and second it doesn't update that property (I think so) 🤔. Using React.useState() works fine 😉, but I think there may be a way to do this with the model the right way ⚒. With the React.useState() look like this:
My question is 🥺, should I use React.useState() for this, or should there be a correct way to perform this experiment 😕? Thanks for reading 🙏🏻, I appreciate any advice and help. Greetings 👋🏻. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Using this block of code I got it to work, but is it the right way?
|
Beta Was this translation helpful? Give feedback.
-
Hi @jojemapa! To access your export const SignInScreen: FC<StackScreenProps<NavigatorParamList, "signIn">> =
observer(({ navigation }) => {
const { userStore } = useStores();
return (
<Screen style={ROOT} preset="scroll">
<Text text={"Username: " + userStore.username} />
<TextInput
value={userStore.username}
onChangeText={(value) => {
userStore.setUsername(value);
}}
/>
</Screen>
);
}); |
Beta Was this translation helpful? Give feedback.
Hi @jojemapa!
To access your
RootStoreModel
instance you can use theuseStores
hook and then use the property you nameduserStore
to access your user.