Reputation: 351
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.
Upvotes: 1
Views: 6117
Reputation: 3274
ProcessInput is returning an object, but you are destructuring it to an array.
Try this:
const {val, bind} = ProcessInput('');
Upvotes: 6