чтобы поменять значение нужно ввести значение в input и нажать на кнопку), как сделать чтобы вводили значение в input и менялось значение без кнопки, это событие onChange?
<input onChange={(event) => {setNewOurPrice(event.target.value)}} className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 w-24 p-2.5" type="number" defaultValue={ product.ourPrice } />
<button onClick={() => {updateOurPrice({ variables: { id: product.id, newOurPrice: Number(newOurPrice) } })}}>Update Password</button>
Number(setNewOurPrice(event.target.value)) - тут что происходит?
магия
const [updateOurPrice] = useMutation(UPDATE_OURPRICE); const [newOurPrice, setNewOurPrice] = useState(''); <input onChange={(event) => { setNewOurPrice(event.target.value) updateOurPrice({ variables: { id: product.id, newOurPrice: Number(newOurPrice) } }) }} type="number" defaultValue={ product.ourPrice } />
вот так переписал, теперь меняется значение, но на 0
Обсуждают сегодня