admin管理员组文章数量:1390697
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('');
本文标签: javascriptReact hooks 39TypeError Object is not a function39Stack Overflow
版权声明:本文标题:javascript - React hooks: 'TypeError: Object is not a function' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744577405a2613710.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论