Estoy tratando de agregar una opción a mi elemento de selección para poder elegir una opción máxima sobre un valor determinado. En este caso, 250. He intentado hacer el operador de comparación mayor que ">" > 250, pero no parece aceptar esa sintaxis. ¿Cómo sería posible hacerlo al máximo?
import { useState } from "react"; import "./styles.css"; export default function App() { const [minPrice, setMinPrice] = useState(0); const [maxPrice, setMaxPrice] = useState(50); const handlePrice = (value) => { switch (value) { case "1": setMinPrice(0); setMaxPrice(50); break; case "2": setMinPrice(50); setMaxPrice(100); break; case "3": setMinPrice(100); setMaxPrice(250); break; case "4": setMinPrice(250); setMaxPrice(>250); //doesn't work break; default: setMinPrice(0); setMaxPrice(50); break; } }; return ( <div className="App"> <select className="custom-select" id="priceGroup" onChange={(event) => handlePrice(event.target.value)} > <option value="1">Under $50</option> <option value="2">$50 to $100</option> <option value="3">$100 to $250</option> <option value="4">Over $250</option> </select> <div>Your min price is {minPrice}</div> <div>Your max price is {maxPrice}</div> </div> ); }
Lo que puedo entender de la pregunta es que desea mostrar "> 250" cuando el usuario selecciona la opción 4. Si es así, setMaxPrice(>250)
no funcionará porque >250
no pertenece a ningún tipo de datos. Podría pasarlo como una cadena como setMaxPrice(">250")
y eso debería funcionar.