I'm trying to pass data
from one React component to another and trying to understand how to call this data
to the target file
Basically you want to pass the <input />
value from component.js
to a function in the Util.js
file.
So far I have tried the following in component.js
:
const [distance, setDistance] = useState(); function handleChange(value){ setDistance(value.target.value); } return { <input className="input" name="distance" type={`number`} onChange={handleChange} /> }
Util.js
export const filterByDistance = function(){ }
So to call it do I need to do something like this?
import {distance} from './component.js';
Don't try to import variables from
component.js
intoUtils.js
, you should do it the other way around: into theUtil.js
function Importcomponent.js
and call it.Then accept the value as parameter: