Overview
TheRouteForm component provides a user interface for entering latitude and longitude coordinates for both the origin (“from”) and destination (“to”) points. It manages the coordinate state and triggers the route finding process.
Props
Callback function invoked when the user clicks “Buscar ruta” (Find Route). Receives the form state containing
from and to coordinates.State
The component maintains the origin and destination coordinates in its internal state:Methods
onChange
Updates the state when coordinate values change in the input fields.The field identifier - either
"from" or "to"The coordinate property to update - either
"lat" or "lng"The new coordinate value
- Takes the current state for the specified field (
fromorto) - Creates a new object with the updated coordinate value
- Merges it back into the state immutably
Render Method
- LatLongFields for origin (“Desde” - From)
- LatLongFields for destination (“Hasta” - To)
- Button that triggers the route search
LatLongFields Integration
The component uses two instances of theLatLongFields component to handle coordinate input:
- Each
LatLongFieldsreceives:id: Identifies which field (“from” or “to”)title: Display label (“Desde” or “Hasta”)value: Current coordinate objectonChange: Handler function for value updates
onChange handler is passed down and called by LatLongFields whenever the user modifies a coordinate value.
Usage Example
Component Structure
File Location
src/client/RouteForm.jsx