iamshaunjp / complete-react-tutorial Goto Github PK
View Code? Open in Web Editor NEWAll course files for the Complete React Tutorial on the Net Ninja YouTube channel.
All course files for the Complete React Tutorial on the Net Ninja YouTube channel.
Hi,
I wrote the following article and would like to update it by showing the blog off as a server side rendered app.
https://medium.com/wasm/server-side-rendering-ssr-using-webassembly-wasm-752841a13439
I have performed the following modifications (very simple procedure) using WasmEdge's React SSR documentation.
https://wasmedge.org/book/en/dev/js/ssr.html
After the above modifications the React blog app builds successfully and can be served without any errors in the terminal/console (server side). However, the web page is not loading on the client side; I believe this could be routing or port related.
Would you like to collaborate briefly on this in order to demonstrate how React apps can be served as SSR using WebAssembly.
Kind regards
Tim
There were no code files for lesson 9
Was there no code done in the video?
Hi I am trying to build the latest lesson in this set (lesson-32).
I get the following error
$ npm run build
> [email protected] build
> react-scripts build
node:internal/modules/cjs/loader:488
throw e;
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" in /home/tpmccallum/SSR/blog/Complete-React-Tutorial/dojo-blog/node_modules/postcss-safe-parser/node_modules/postcss/package.json
at new NodeError (node:internal/errors:372:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
at packageExportsResolve (node:internal/modules/esm/resolve:719:3)
at resolveExports (node:internal/modules/cjs/loader:482:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/tpmccallum/SSR/blog/Complete-React-Tutorial/dojo-blog/node_modules/postcss-safe-parser/lib/safe-parser.js:1:17) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
I would like to get this blog working as a server-side rendered app as per the following tutorial (which takes a create-react-app
style app and delegates the JavaScript UI rendering to a server). The reason I chose this repository is because it follows the create-react-app closely in terms of convention and layout etc. and therefore is possibly the best app to test converting a React app to SSR
If you followed the video tutorial to the end and do not see the site displaying the previews for mario's blogs, the simple issue is that 'blog' is suppose to be 'blogs'.
<BlogList blogs={blogs.filter(blog => blog.author === 'mario')} title="Mario's Blogs" />
=>
<BlogList blogs={blogs.filter(blogs => blog.author === 'mario')} title="Mario's Blogs" />
I have encountered a syntax change related to the id field in the json-server package when upgrading to version 1.0.0-alpha.20. The id field of an data object was previously an integer, and in the updated version, it is expected to be a string.
Consider this example form "https://www.npmjs.com/package/json-server":
{
"posts": [
{ "id": "1", "title": "a title" },
{ "id": "2", "title": "another title" }
],
"comments": [
{ "id": "1", "text": "a comment about post 1", "postId": "1" },
{ "id": "2", "text": "another comment about post 1", "postId": "1" }
],
"profile": {
"name": "typicode"
}
}
Thanks for creating this tutorial! I've watched (nearly) the whole tutorial but I'm unsure about the license.
Am I allowed to use your source code? And am I allowed to adopt it?
I think that it would be pretty nice to have a License for the source code. I do not want to copy your videos or something other - I'd just like to reuse some of your code... Is there a license for the source code?
Hi! If you want to go directly to the created post, you need to do the next thing:
Привiт! Якщо ви хочете відразу перейти в щойно створений пост, вам потрібно зробити наступне:
fetch('http://localhost:8000/blogs',{
method: 'POST',
headers:{"Content-Type":"application/json"},
body: JSON.stringify(blog)
})
.then(response =>{return response})
.then(response => response.json())
.then((response) => history.push('/blogs/' + response.id))
add setData(null); in catch block in useFetch.js
as we done before, we have added a handleDelete function to the bloglist ... but we deleted it later and in lesson 31 we added a delete function in blogdetails ( handleClick ) ...
now I want to link the detele button in the blogList to the handleClick which located in blogDetails.js
can u help me regarding this issue ?
On #8 video react tutorial after using useState hook, when i recopy the code from the video to my code, i cant apply that to the live site?
Start showing this:"Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.".
Any help, please?
Hi and thanks a lot for your amazing tutorial. Could you advise me please what could be wrong?
I think I did everything like you in tutorial, but in lesson 23, in a moment I overwrite <a>
tag with <Link>
tag the error comes.
Error: Invariant failed: You should not use <Link>
outside a <Router>
I even copied the code from git to check it, but there is still something wrong.
Thanks for all tips.
Petr
I have question why i`m getting this error?
Unexpected token '<', "<!DOCTYPE "... is not valid JSON
in useFetch.js we are returning
return res.json();
Uncaught (in promise) Error: The message port closed before a response was received.
This occurs on the 1st "Click Me" request.
It's not like an issue, I was just following your amazing work from YouTube and you have forgotten to change console.log(blog) to console.log(name) in useEffect part.
When deleting a blog in blogDetails Component it gives blogs.filter is not function
const handleDelete =() => {
fetch(${ApiUrl} ${blogs.id}
, {
method: "DELETE"
}).then(() => {
setDeleteBlogs((blog=>blog.id!==id));
navigate('/');
})
.catch((err)=>{
console.log(err.message);
})
}
tamilvip007@indrajeeth-PC:/media/tamilvip007/DISK :)/VS/filemanager$ npm run start
[email protected] start
react-scripts start
sh: 1: react-scripts: not found
Most of the REACT stuffs your taught are giving errors, please can you make a tutorial for new WHEN USING REACT DOM 6, PLEASE!!
Hi Shaun,
THANKS for incredible videos!
I have a small question concerning state update, when we delete a blog record directly from Home
in BlogList
component, not in BlogDetails
.
In Lesson 13 we've used the callback function to handle delete:
import { useState } from "react";
import BlogList from "./BlogList";
const Home = () => {
const [blogs, setBlogs] = useState([
{ title: 'My new website', body: 'lorem ipsum...', author: 'mario', id: 1 },
{ title: 'Welcome party!', body: 'lorem ipsum...', author: 'yoshi', id: 2 },
{ title: 'Web dev top tips', body: 'lorem ipsum...', author: 'mario', id: 3 }
])
const handleDelete = (id) => {
const newBlogs = blogs.filter(blog => blog.id !== id);
setBlogs(newBlogs);
}
return (
<div className="home">
<BlogList blogs={blogs} title="All Blogs" handleDelete={handleDelete} />
</div>
);
}
export default Home;
const BlogList = ({ blogs, title, handleDelete }) => {
return (
<div className="blog-list">
<h2>{ title }</h2>
{blogs.map(blog => (
<div className="blog-preview" key={blog.id} >
<h2>{ blog.title }</h2>
<p>Written by { blog.author }</p>
<button onClick={() => handleDelete(blog.id)}>delete blog</button>
</div>
))}
</div>
);
}
export default BlogList;
Then in Lesson 31 we've moved all logic to useFetch
hook, so state is updated for BlogDetails
page:
import { useHistory, useParams } from "react-router-dom";
import useFetch from "./useFetch";
const BlogDetails = () => {
const { id } = useParams();
const { data: blog, error, isPending } = useFetch('http://localhost:8000/blogs/' + id);
const history = useHistory();
const handleClick = () => {
fetch('http://localhost:8000/blogs/' + blog.id, {
method: 'DELETE'
}).then(() => {
history.push('/');
})
}
return (
<div className="blog-details">
{ isPending && <div>Loading...</div> }
{ error && <div>{ error }</div> }
{ blog && (
<article>
<h2>{ blog.title }</h2>
<p>Written by { blog.author }</p>
<div>{ blog.body }</div>
<button onClick={handleClick}>delete</button>
</article>
)}
</div>
);
}
export default BlogDetails;
And what if I want to add delete button directly to the BlogList
component to delete a blog record from Home page?
What is the easiest or the best approach to achieve something like this?
Notice handleDeleteClick
is in BlogList
not in BlogDetails
.
import { Link } from "react-router-dom";
const BlogList = ({blogs, title}) => {
const handleDeleteClick = (id) => {
fetch(`http://localhost:8000/blogs/${id}`, {
method: 'DELETE'
});
}
return (
<div className="blog-list">
<h2>{title}</h2>
{blogs.map((blog) => (
<div className="blog-preview" key={blog.id}>
<Link to={`/blogs/${blog.id}`}>
<h2>{blog.title}</h2>
<p>Written by {blog.author}</p>
<button onClick={ () => handleDeleteClick(blog.id) }>delete</button>
</Link>
</div>
))}
</div>
);
}
export default BlogList;
import './BlogList'
import BlogList from "./BlogList";
import useFetch from "./hooks/useFetch";
const Home = () => {
const {data: blogs, isPending, error} = useFetch('http://localhost:8000/blogs');
return (
<div className="home">
{ error && <div className="fetchError"> {error} </div>}
{isPending && <div className="loading">loading...</div>}
{blogs && <BlogList blogs={blogs} title="All Blogs" />}
</div>
);
}
export default Home;
Thanks!
Uncaught runtime errors:
×
ERROR
Cannot destructure property 'data' of '(0 , useFetch__WEBPACK_IMPORTED_MODULE_2_.default)(...)' as it is null.
TypeError: Cannot destructure property 'data' of '(0 , useFetch__WEBPACK_IMPORTED_MODULE_2_.default)(...)' as it is null.
at Home (http://localhost:3000/main.cc6b4c03545d80ef5a52.hot-update.js:72:11)
at renderWithHooks (http://localhost:3000/static/js/bundle.js:21462:22)
at mountIndeterminateComponent (http://localhost:3000/static/js/bundle.js:24748:17)
at beginWork (http://localhost:3000/static/js/bundle.js:26044:20)
at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:11054:18)
at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:11098:20)
at invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:11155:35)
at beginWork$1 (http://localhost:3000/static/js/bundle.js:31029:11)
at performUnitOfWork (http://localhost:3000/static/js/bundle.js:30276:16)
at workLoopSync (http://localhost:3000/static/js/bundle.js:30199:9)
ERROR
Cannot destructure property 'data' of '(0 , useFetch__WEBPACK_IMPORTED_MODULE_2_.default)(...)' as it is null.
TypeError: Cannot destructure property 'data' of '(0 , useFetch__WEBPACK_IMPORTED_MODULE_2_.default)(...)' as it is null.
at Home (http://localhost:3000/main.cc6b4c03545d80ef5a52.hot-update.js:72:11)
at renderWithHooks (http://localhost:3000/static/js/bundle.js:21462:22)
at mountIndeterminateComponent (http://localhost:3000/static/js/bundle.js:24748:17)
at beginWork (http://localhost:3000/static/js/bundle.js:26044:20)
at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:11054:18)
at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:11098:20)
at invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:11155:35)
at beginWork$1 (http://localhost:3000/static/js/bundle.js:31029:11)
at performUnitOfWork (http://localhost:3000/static/js/bundle.js:30276:16)
at workLoopSync (http://localhost:3000/static/js/bundle.js:30199:9)
ERROR
Cannot destructure property 'data' of '(0 , useFetch__WEBPACK_IMPORTED_MODULE_2_.default)(...)' as it is null.
TypeError: Cannot destructure property 'data' of '(0 , useFetch__WEBPACK_IMPORTED_MODULE_2_.default)(...)' as it is null.
at Home (http://localhost:3000/main.cc6b4c03545d80ef5a52.hot-update.js:72:11)
how to solve this error
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.