ExpoBeginner
TextInput ও useState — ফর্ম তাদের সহজ নিয়ম
controlled TextInput-ফর্ম — useState দিয়ে — বাংলায়।
4টি অংশবাংলা ভাষায়
components/TaskForm.tsxtsx
tsx
import { useState } from "react";
import { TextInput, Pressable, Text, View } from "react-native";
export default function TaskForm({ onSubmit }) {
const [title, setTitle] = useState("");
return (
<View>
<TextInput
value={title}
onChangeText={setTitle}
placeholder="নতুন কাজের নাম"
style={{ borderWidth: 1, padding: 12, borderRadius: 8 }}
/>
<Pressable onPress={() => onSubmit(title)}>
<Text>যোগ করুন</Text>
</Pressable>
</View>
);
}value+onChangeText— controlled patternkeyboardType— numeric / emailreturnKeyType— done, nextmultiline— বড় text
Validation সহজ রাখুন — submit-এ empty check, প্রয়োজনে error message দেখান।
controlled ফিল্ড
controlled মানে value React-এর হাতে — TextInput-এর একটাই নিয়ম: value আর onChangeText জোড়া।
শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।