Unable to render the Post page in NextJS

The array of an object is listed as follows just to give you an idea.. { id : 1, image: "/image" title: dfdhfdjfh description: dfhdkfhd } I built the same in ReactJs and it works fine but not able to in NextJS. I have been at this for whole day. Can someone guide me?
No description
23 Replies
lko
lko2mo ago
You're saying posts with the s, so i guess it's an array You should map trough your post and then render each one of them
Popo
Popo2mo ago
I did that with post and since it was not working i was adding s to all of them and trying... ...
lko
lko2mo ago
can you show the code? and how have you tried with post?
Popo
Popo2mo ago
I just removed the "s" let me paste it here. "use client" import React from 'react'; import { useParams } from "next/navigation"; import Lifelist from "./lifelist"; import styles from "./page.module.css" import Image from 'next/image'; const LifePost = () => { const { id } = useParams(); const post = Lifelist.find((post) => post.id === parseInt(id)); return ( <>
<div> <h1>what is this</h1> <img className={styles.picture} src={post.image} alt={post.title} /> <h1 className={styles.posttitle}>{post.title}</h1> <div className={styles.blogpost}>
<p className={styles.bodyText}>{post.description}</p> {/* Assuming 'content' is the detailed post */} </div> </div> </> ); }; export default LifePost;
lko
lko2mo ago
Do you have some experience with plain js/css and html?
Popo
Popo2mo ago
I do.
lko
lko2mo ago
what error does it give you if try it with post?
Popo
Popo2mo ago
same error in the pic i shared above. It says the image is undefined.
lko
lko2mo ago
Try this
"use client"

import React from 'react';
import { useParams } from "next/navigation";
import Lifelist from "./lifelist";
import styles from "./page.module.css"
import Image from 'next/image';

const LifePost = () => {
const { id } = useParams();
const post = Lifelist.find((post) => post.id === parseInt(id));

return (
<>
<div>
<h1>what is this</h1>
{post && (
<>
<img className={styles.picture} src={post.image} alt={post.title} />
<h1 className={styles.posttitle}>{post.title}</h1>
<div className={styles.blogpost}>
<p className={styles.bodyText}>{post.description}</p> {/* Assuming 'content' is the detailed post */}
</div>
</>
)}
{!post && <p>Post not found</p>}
</div>
</>
);


};

export default LifePost;
"use client"

import React from 'react';
import { useParams } from "next/navigation";
import Lifelist from "./lifelist";
import styles from "./page.module.css"
import Image from 'next/image';

const LifePost = () => {
const { id } = useParams();
const post = Lifelist.find((post) => post.id === parseInt(id));

return (
<>
<div>
<h1>what is this</h1>
{post && (
<>
<img className={styles.picture} src={post.image} alt={post.title} />
<h1 className={styles.posttitle}>{post.title}</h1>
<div className={styles.blogpost}>
<p className={styles.bodyText}>{post.description}</p> {/* Assuming 'content' is the detailed post */}
</div>
</>
)}
{!post && <p>Post not found</p>}
</div>
</>
);


};

export default LifePost;
Popo
Popo2mo ago
Improved but not working still. It says post not found..
lko
lko2mo ago
Ok, it means that the post was not found in the array, it means you're trying to find a post with the id parseInt(id) but there's none in the array So the problem is there
Popo
Popo2mo ago
{ id: 2, image: "/happyee.webp", title: "What the is dfdfd dfdf dfdf dfd going here", description: "lorem ipsd dfjdk s ffjdkfj s.lf lsjf slf sf s fjslfosjf sf s sfjs ffslfj sfls fs", }, This is an example of the array. Why would not if find it
lko
lko2mo ago
do a console.log of Lifelist and id
Popo
Popo2mo ago
No description
Popo
Popo2mo ago
it is there.
lko
lko2mo ago
which one is supposed to be the Id?
Popo
Popo2mo ago
I am sorry it is for the lifelist only
Popo
Popo2mo ago
No description
Popo
Popo2mo ago
It says undefined in the 11 line that is where i console.log id
lko
lko2mo ago
That's why
Popo
Popo2mo ago
How do i fix this. where am i doing wrong?
Popo
Popo2mo ago
Thanks a lot!!! Have a great day!!
Want results from more Discord servers?
Add your server