React Components, Props, and State Management

Course Overview and Interactive Architecture

Mobile Web App Development (CP50093E) at the University of West London, instructed by Dr Omar Al Hashimi, establishes the progression from static user interfaces to dynamic React applications. Static implementations follow a linear flow from component to JSX to user interface. Interactive user interfaces integrate components, data, state, and events to handle real-time user engagement.

Props in React Components

Props serve as the mechanism for passing input data from a parent component to a child component, enabling a single component definition to render varying data across instances. Defined in files such as Product.jsx and consumed in parent files such as App.jsx, props are strictly read-only inputs that must never be modified by the receiving component. For example, rendering <Product name="Laptop" id="P101" datePurchased="04/10/2026" /> delivers structured attributes into the component for display.

State Management and the useState Hook

State stores dynamic information that changes during runtime within an individual component. Functional components manage local state using the React.useState Hook, which declares a state variable and an updater function, exemplified by const [productId, setProductId] = React.useState(''). Initialized to an empty string, productId holds the current value, while invoking setProductId("P102") updates the value and prompts React to re-render the user interface.

User Input and Controlled Components

Product input form showing ID, Name, Date Purchased fields, and action buttons

Form elements such as <input> and <button> capture user actions and bind them to state. Controlled inputs connect through the attributes value={productId} and onChange={(e) => setProductId(e.target.value)}. This establishes the complete data flow: the user inputs data, an event fires, state updates via the setter function, and React updates the user interface. Button actions trigger designated event handlers via onClick, executing functions such as showClickHandler or clearClickHandler to clear or display form values.

Questions & Discussion

Question: Outside JSX, which is the correct way to refer to the state value? Options: a) productId, b) {productId}. Answer: productId.

Question: Inside JSX, which is the correct way to display the state value? Options: a) productId, b) {productId}. Answer: {productId}.

Question: Which function should we use to update the Product ID? Options: a) productId("P102"), b) setProductId("P102"). Answer: setProductId("P102").

Quick Activity: What happens when clearClickHandler() is called, containing setProductId(' ');, setProductName(' ');, and setProductDatePurchased(' ');? Options: a) The three values are set to blank, b) The values remain unchanged, c) An error occurs. Response: The values are updated and set to blank strings.