✅ dotnet new react - with mvc?
I want to learn and use React. How do I create an app that uses both react and mvc using cli?
I can only create web app and that's razor pages I guess? Or is it Single page application? No idea what it is.
34 Replies
dotnet new react
will do the trickWhat kind of app does it create?
WebAPI project with the SPA middleware
webapp or api?
WebAPI
Oh so it's client side requesting to back end, which makes it count as api?
Well, yes, that's how APIs work generally
A client app sends requests to the backend
In the apps I know, there is a webapp, one with client side... and I can create an api for other apps to use.
Is that how it is normally?
?
There's an API that runs on the server
That is all that runs on the server
Then, there's your React app that's the client
You can have other clients as well
Wait a minute, all back end apps count as api or what?
No?
You can have an MVC or Razor Pages app that will be rendered server-side
Normally I use donet new mvc -o MyProject. What does this create?
It won't have an API
It creates an MVC project with Razor views
It's rendered entirely server-side
You can add API controllers to it, sure
That's what I did then
But by default it is not an API
That's what confused me about react app
React app is like a software that is completely given to user, and I have an api which react app sends requests to here?
Yep
The backend API does not render any HTML, it just provides data as JSON
All rendering is done by React on the client side
Wow. Then could this also be used for a mobile app or something? By sending requests to end points of this api
Sure
As I said, anything can be a client
Even another API
Awesome, but apis can also be mvc. It didn't give me an mvc structure by default so I thought I needed some extra cli command next to react but that didn't work.
With ASP you can mix and match, in general
It's just I like mvc more
You can add MVC with Razor views to your Razor Pages project
And you can add API controllers on top
Or you can add a Razor page to your API
And slap some Blazor Server components on top
Wait, I didn't go into any razor page stuff before so I am confused here a little. React is client side, a virtual dom. Why should it have razor pages?
wait, mvc have views too, why would I need those...
You can have those
I see, what do they do 😄
Not saying you should
What does what do?
views/pages
Render HTML server-side
Then send already rendered HTML to the browser
You know what, I won't ask you to tell me this on top of virtual dom stuff that I already know nothing about. Let's keep it simple
I see the controllers folder in react app. All I need is creating Models folder, that's it 😄
Another thing is, is this react app single page application by default as it should be?
SPA that changes asynchronously changes the dom?
¯\_(ツ)_/¯
Never really used React
But I'd assume it changes the DOM... when you tell it to change the DOM
I was just wondering if react, anguler, vue etc are all spas
Yep
no need for server side rendering
It got cleared so much
yay, level up
love this channel