-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could you write in more detail how to run the mock server? #4
Comments
Hi @dmitrybv , You can still read more about the mock server in step 5 of the Redux Essentials trail. I also raised an issue about this there. Let me know if I can help any more. Since I didn't create that, |
I replaced the lines in postsSlice.ts // export const fetchPosts: any = createAsyncThunk(
// "posts/fetchPosts",
// async () => {
// const response = await axios.get(API_URL+"/posts");
// return response.data;
// }
// );
const dateSub10 = sub(new Date(), { minutes: 10 }).toISOString();
const initialStatePosts: Post[] = [
{
id: "1",
title: "First Post!",
content: "Hello!",
user: "0",
date: dateSub10,
reactions: { thumbsUp: 0, hooray: 0, heart: 0, rocket: 0, eyes: 0 },
},
{
id: "2",
title: "Second Post",
content: "More text",
user: "1",
date: dateSub10,
reactions: { thumbsUp: 0, hooray: 0, heart: 0, rocket: 0, eyes: 0 },
},
];
export const fetchPosts: any = createAsyncThunk(
"posts/fetchPosts",
async () => {
return new Promise<Post[]>((resolve, reject) => {
setTimeout(() => {
if (Math.random() > 0.95) {
reject(new Error('Something bad happened'));
} else {
resolve(initialStatePosts);
}
}, 1500);
});
}
); And the application partially began to work. At least the list of posts began to be issued. Does it make sense to use axios and external calls in order to show an example of how the frontend application works? |
Yes, that's probably the easiest way to go. My plan was to take the code as a blueprint for best practices and also add real-world functionality that the demo is missing. This would include authentication and an actual backend. With that in mind, it seemed like a good idea to start with a real backend to deal with the async data section. Anyhow, thanks for your input on this matter. For someone who just wants to focus on the Redux with Typescript, that's the best solution. Do you have any plans to continue on to the next step: Redux Essentials, Part 6: Performance and Normalizing Data? I am half way through that section now and will update this repo with that soon. |
I just started learning Redux and am learning TypeScript at the same time. |
Do I see it correctly that there is no full-fledged Demo project written in TypeScript in the official React documentation now? |
Do you use this project |
After I added next code
to src\index.tsx and installed required packages for server.js I started to get strange compiling errors like this:
Have you experienced this? |
Regarding the project. From the beginning I started the app using create react app with the typescript flag and wrote about converting the counter example as detailed in this article:
I did not take the completed project and convert the whole thing. If you look at the commit history for this project, you should see a commit for each step in the tutorials. Starting is step 3 of the redux essentials trail I went through each step, using the code as introduced in the tutorials and converted each step to typescript one at a time as show in this article. If you are just getting started with this, and want to run a TypeScript version, I would recommend just looking at the code at the end of step-4: https://github.com/timofeysie/redux-typescript-example/tree/part-4-reaction-buttons In step 5, the fakeApi is starting to get used, which causes all kinds of weird issues that I can't help you with. You could create demo data with promises as you showed before. |
In the article
It is NestJS, not Next.js. |
Good catch @dmitrybv! I think I was rushing a bit when I wrote that. Since the React team has published it's new docs that no longer support create-react-app (which this project was started with), it means the Redux team will also be updating their docs with new material, meaning this project will become a bit of a dead end. I think it's still helpful for now for people who want to work on a current project that was started with the previously standard method. |
You wrote allowJs in tsconfig.json two times. |
I managed to convert client.js, server.js to TypeScript and make it work in fetchPosts |
That's great work @dmitrybv. I had a look at the TS errors when evaluating converting those files, and thought it would take a while. You should let the official app maintainer Mark Erikson know on the ticket I raised there. I will have to add to this project the ability to either use the fakeApi or your own custom API by setting the REACT_APP_API_URL in the .env file. |
Hello.
Could you write in more detail how to run the mock server?
The text was updated successfully, but these errors were encountered: