I'm using React version 16.13.1.
I'm getting 'TypeError: Object is not a function'
Here is my code (error message seems to think something is wrong with line 7):
import React, { useState } from 'react';
import fb from '../config/firebase';
import ProcessInput from './customHooks/processInput';
const DashBoard = ({ level, newUser }) => {
const [val, bind] = ProcessInput('');
const handleChange = (e) => {
e.preventDefault();
}
Here is my custom hook:
import { useState } from 'react';
export const ProcessInput = value => {
const [val, setVal] = useState(value);
return {
val,
setVal,
bind: {
val,
onChange: event => {
setVal(event.target.value);
}
}
};
};
Thanks in advance for your help.
I'm using React version 16.13.1.
I'm getting 'TypeError: Object is not a function'
Here is my code (error message seems to think something is wrong with line 7):
import React, { useState } from 'react';
import fb from '../config/firebase';
import ProcessInput from './customHooks/processInput';
const DashBoard = ({ level, newUser }) => {
const [val, bind] = ProcessInput('');
const handleChange = (e) => {
e.preventDefault();
}
Here is my custom hook:
import { useState } from 'react';
export const ProcessInput = value => {
const [val, setVal] = useState(value);
return {
val,
setVal,
bind: {
val,
onChange: event => {
setVal(event.target.value);
}
}
};
};
Thanks in advance for your help.
Share Improve this question edited Apr 26, 2020 at 16:40 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Apr 26, 2020 at 13:24 JoshuaRDBrownJoshuaRDBrown 3515 silver badges12 bronze badges 2- Please post actual code, not pictures of it. – jmargolisvt Commented Apr 26, 2020 at 13:27
-
1
Names of custom hooks should start with
use
, see reactjs/docs/hooks-custom.html#extracting-a-custom-hook – rrebase Commented Apr 26, 2020 at 13:29
1 Answer
Reset to default 6ProcessInput is returning an object, but you are destructuring it to an array.
Try this:
const {val, bind} = ProcessInput('');