import ReactDOM from "react-dom";
import React, { Fragment, useState, useCallback } from "react";
const ProcessingSearch = () => {
const [price, setPrice] = useState({ maxPrice: 0, minPrice: 0 });
const [solde, setSolde] = useState(0);
const inputMaxMin = useCallback(
({ target: { value, name } }) => {
name === "maxPrice"
? setPrice(({ minPrice }) => ({ maxPrice: value, minPrice }))
: setPrice(({ maxPrice }) => ({ minPrice: value, maxPrice }));
},
[price]
);
return (
<Fragment>
<form onSubmit={() => {}}>
{"Min"}
<input value={price.minPrice} onChange={inputMaxMin} />
{"Max"}
<input value={price.maxPrice} onChange={inputMaxMin} />
<input type="submit" title={"Submit price range"} value={"Go"} />
</form>
<div onClick={() => setSolde(solde + 1)}>{solde}</div>
</Fragment>
);
};
const rootElement = document.getElementById("root");
ReactDOM.render(<ProcessingSearch />, rootElement);
Когда я использую price, я получаю сообщение об ошибке:
React Hook useCallback has an unnecessary dependency: 'price'. Either exclude it or remove the dependency array.