Hello, i try .map my state but he dont work ,
in my consol i have this : Object[[Prototype]]
my code :https://github.com/GOANEX32/P7groupomania/blob/main/frontend/src/components/Post/Card.js
Where is this console statement?
At the very least I would want to console.log('Card postData', postData)
. If that didn’t answer my question, I’d do the same inside the map callback, and if that didn’t find the problem, I’d do the same in each of the sub components.
You are the one that has a working version of the app, you need to be the detective.
You could also create dummy data and use it as your initial state just to get it working. I’m a little confused as to why you have your initial state for your posts as an object.
line 15 for console log
And what is the output?
I gave you several steps for a basic debugging strategy. At this point you should at least be able to figure out where your code is failing, even if you don’t know why,
OK, do you remember when I said
I’m a little confused as to why you have your initial state for your posts as an object.
You should figure that out.
And what do you expect to happen here? Is it supposed to have data?
Yes is supposed have my data post
- Why are you initializing it to an object? (This is the third time I’ve asked.)
- You seem to think it should have something other than the initial state. Where have you given it something other than the initial state?
- What have you done to confirm that the state is being changed?
- Give your posts an initial state of some dummy posts. What happens? (Seriously, I would have built this with dummy data first and not removed it until It was working.)
It seems like you only read half a sentence of each of my posts and ignore the rest. This has gone on in a couple threads now. You think I’m trying to fix your code - I’m not. I have no interest in that. I’m trying to teach you how to fix your code. Please help me do that by trying advice when given and answering questions.
Sorry my english is bad (my code too ^^) ,
1 i dont know if i initializing object or not , i use my store reducer like tuto
2 maybe i can try push data state in a array
3 nothing
4 your want i use this : const [post, setPost] = useState; ?
thank your for try teach me
i find the problem in my post action
Sorry my english is bad …
That’s fine, I’m used to it - most of the people I work with don’t speak English as a first language. But getting better at English will be good - there will be more opportunities. You don’t have to be an expert, quoting Shakespeare and such, just be able to talk about code.
(my code too ^^) ,
It’s no worse than my code was when I was learning.
1 i dont know if i initializing object or not , i use my store reducer like tuto
But try to understand what is happening.
Your state is initialized in post.reducer.js:
const initialState = {};
export default function postReducer(state = initialState, action) {
When the reducer is first called, state is undefined, so it uses initialState. That is my confusion. If posts is supposed to be an array of posts, why is it initialized with an empty object? I would expect an empty array. If you wanted, you could put some fake posts in there to start out, for testing, and so you could work on the other parts of the app.
2 maybe i can try push data state in a array
I’m not sure I understand. You should either do it “normally”, but using the app, or by using the initial state, as I mention above.
3 nothing
If I wasn’t sure, I’d put log statements inside the reducer. I might put useState(state => console.log('state', state)
in my component so I could watch it get update. There are also browser tools like redux dev tools that let you observe what is happening.
4 your want i use this : const [post, setPost] = useState; ?
No. That should only be used for things that are local. Your posts are needed in other parts of the app so redux is a better place.
i find the problem in my post action
Cool, good job.
An important part of being a good debugger. And being a good debugger means being a good detective.
On the job, you can’t go to another develop, hand then 2000 lines of code and say, “this doesn’t work, fix it”. You can go to another coder and say, “This isn’t working and I’ve narrowed it down to this line of code - What am I missing?”
Learn to at least find where the problem is. And often you’ll see the solution. There are many problems at work where I am writing up the explanation of what is confusing me, and in the process I find the solution.
Ok , improv my english and work like detective
I’m more worried about your debugging skills. English will come with time. And English is not necessary to become a developer, it just creates more job opportunities. But it will come with time.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.