Terms
Components
- Functions in React and JSX are called Components
Parent Component: Any component that renders other components is called Parent. Example Cat is parent and fun is child Component.
1. Text Component
- Used to show text
|
1. Import React Native’s Text Core Component 2. component starts as a function
Whatever a function component returns is rendered as a React element. 3. We can call function from inside of {} 4. export the function using default |
2. View Component
- Used to embed 2 or more components(eg: text, textinput)
|
1. Import Text, View, TextInput 2. ViewComp() function returns View component. Text, TextInput are placed inside it 3. Call function from default component 4. We can call 1 function multiple times to avoid writing same code again and again |
Props / Properties
-
Props means something which can be passed to Components. Eg: struct, string etc
|
1. prop declared 2. Component accepts prop as argument 3. Prop passed while calling the function. We have passed value to name, this should be exactly same as variable name inside Prop. |
State (local variable)
-
State is useful for handling data that changes over time or that comes from user interaction
|
1. import useState from React 2. Create hungry state variable inside the function. Initialize the true we can use useState to track any kind of data: strings, numbers, Booleans, arrays, objects. For example, const [counter, setCounter] = useState(0)! Function setHungry() will used to set value of variable hungry 3. Add button component 4. Wrap inside JSX fragments |