project_mern_memories icon indicating copy to clipboard operation
project_mern_memories copied to clipboard

TypeError: setCurrentId is not a function

Open mesushant13 opened this issue 3 years ago • 11 comments

TypeError: setCurrentId is not a function onClick E:/project1/client/src/components/Posts/Post/Post.js:23 20 | <Button 21 | style={{ color: 'white' }} 22 | size="small"

23 | onClick={() => setCurrentId(post._id)}><MoreHorizIcon fontSize="default" /></Button> | ^ 24 | 25 | <div className={classes.details}> 26 | <Typography variant="body2" color="textSecondary">{post.tags.map((tag) => #${tag} )}</Typography>

mesushant13 avatar Jun 21 '21 15:06 mesushant13

even i am facing the same exact problem. have you found the solution. i would be grateful if you share.

ram-kp avatar Jul 01 '21 07:07 ram-kp

yeah I found it it's just a bracket issue

On Thu, Jul 1, 2021 at 12:32 PM ram pandey @.***> wrote:

even i am facing the same exact problem. have you found the solution. i would be grateful if you share.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/adrianhajdin/project_mern_memories/issues/46#issuecomment-871980455, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALHFB4UJYUXRSP6SHNBDEZDTVQHH7ANCNFSM47BYSUGQ .

mesushant13 avatar Jul 01 '21 07:07 mesushant13

@mesushant13 Have you found that issue? tell me plzz

syedasifali548 avatar Jul 20 '21 19:07 syedasifali548

In clear() function of client/src/components/Form/Form.js

const clear = () => { setCurrentId = 0; //<==========Solution setPostData({ creator: "", title: "", message: "", tags: "", selectedFile: "", }); };

ashxmaker avatar Aug 16 '21 19:08 ashxmaker

I am facing the same problem. finally I just found that I made a mistake. {} => [] it's const [currentId, setCurrentId] = useState(0); not const {currentId, setCurrentId} = useState(0);

Hyman1993 avatar Dec 20 '21 13:12 Hyman1993

You need to pass the props to other components inside the curly braces => {} Something like this: const Posts = ({ setCurrentId }) => { // Our Code.... }

If you forget to type those curly braces there, you'll face the same error I was getting :)

MatinT-SA avatar Mar 04 '22 19:03 MatinT-SA

TypeError: setCurrentId is not a function onClick E:/project1/client/src/components/Posts/Post/Post.js:23 20 | <Button 21 | style={{ color: 'white' }} 22 | size="small"

23 | onClick={() => setCurrentId(post._id)}> | ^ 24 | 25 | 26 | {post.tags.map((tag) => #${tag} )}

make sure you pass the right setCurrentId as an argument from App.js and from Posts.js: I also had the same issue-> the problem was that I misspelled setCurrentId(I forgot a 't'. I wrote setCurrenId instead of setCurrentId) in App.js. It took some time to catch that, hope it will help somebody

GuyTdev avatar Apr 11 '22 09:04 GuyTdev

I am getting TypeError: a.map is not a function it points to map() this in the code and I cannot figure what I am doing wrong. Please help. I just finished part 3. Thank you!

client/components/Posts/Posts.js import React from 'react'; import { Grid, CircularProgress } from '@material-ui/core'; import { useSelector } from 'react-redux'; import Post from './Post/Post'; import useStyles from './styles';

const Posts = ({ setCurrentId }) => { const posts = useSelector((state) => state.posts); const classes = useStyles();

return ( !posts.length ? <CircularProgress /> : ( <Grid className={classes.container} container alignItems="stretch" spacing={2}> {posts?.map((post) => ( <Grid key={post._id} item xs={12} sm={12} md={6} lg={3}> <Post post={post} setCurrentId={setCurrentId} /> </Grid> ))} </Grid> ) ); };

export default Posts;

PamelaCaguana avatar May 05 '22 06:05 PamelaCaguana

@PamelaCaguana I think you need to destructure the posts like this: const { posts } = useSelector((state) => state.posts);

MatinT-SA avatar May 05 '22 15:05 MatinT-SA

I am getting TypeError: a.map is not a function it points to map() this in the code and I cannot figure what I am doing wrong. Please help. I just finished part 3. Thank you!

client/components/Posts/Posts.js import React from 'react'; import { Grid, CircularProgress } from '@material-ui/core'; import { useSelector } from 'react-redux'; import Post from './Post/Post'; import useStyles from './styles';

const Posts = ({ setCurrentId }) => { const posts = useSelector((state) => state.posts); const classes = useStyles();

return ( !posts.length ? : ( {posts?.map((post) => ( ))} ) ); };

export default Posts;

Try to replace this line: return ( !posts.length ? : ( {posts?.map((post) => ( ))} )

with-> return ( !posts.length ? : ( {posts.map((post) => ( ))} )

GuyTdev avatar May 06 '22 15:05 GuyTdev

With both servers not running locally, the front end doesn't treat my data as an array and map() is an array method. Since my posts are not loading properly the site breaks. I'm going to continue on. I tried both suggestions but they didn't do it for my particular repo.

Thank you for your help!

PamelaCaguana avatar May 10 '22 17:05 PamelaCaguana