C
C#2y ago
İrşat

✅ 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
Angius
Angius2y ago
dotnet new react will do the trick
İrşat
İrşat2y ago
What kind of app does it create?
Angius
Angius2y ago
WebAPI project with the SPA middleware
İrşat
İrşat2y ago
webapp or api?
Angius
Angius2y ago
WebAPI
İrşat
İrşat2y ago
Oh so it's client side requesting to back end, which makes it count as api?
Angius
Angius2y ago
Well, yes, that's how APIs work generally A client app sends requests to the backend
İrşat
İrşat2y ago
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?
Angius
Angius2y ago
? 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
İrşat
İrşat2y ago
Wait a minute, all back end apps count as api or what?
Angius
Angius2y ago
No? You can have an MVC or Razor Pages app that will be rendered server-side
İrşat
İrşat2y ago
Normally I use donet new mvc -o MyProject. What does this create?
Angius
Angius2y ago
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
İrşat
İrşat2y ago
That's what I did then
Angius
Angius2y ago
But by default it is not an API
İrşat
İrşat2y ago
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?
Angius
Angius2y ago
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
İrşat
İrşat2y ago
Wow. Then could this also be used for a mobile app or something? By sending requests to end points of this api
Angius
Angius2y ago
Sure As I said, anything can be a client Even another API
İrşat
İrşat2y ago
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.
Angius
Angius2y ago
With ASP you can mix and match, in general
İrşat
İrşat2y ago
It's just I like mvc more
Angius
Angius2y ago
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
İrşat
İrşat2y ago
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...
Angius
Angius2y ago
You can have those
İrşat
İrşat2y ago
I see, what do they do 😄
Angius
Angius2y ago
Not saying you should What does what do?
İrşat
İrşat2y ago
views/pages
Angius
Angius2y ago
Render HTML server-side Then send already rendered HTML to the browser
İrşat
İrşat2y ago
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?
Angius
Angius2y ago
¯\_(ツ)_/¯ Never really used React But I'd assume it changes the DOM... when you tell it to change the DOM
İrşat
İrşat2y ago
I was just wondering if react, anguler, vue etc are all spas
Angius
Angius2y ago
Yep
İrşat
İrşat2y ago
no need for server side rendering It got cleared so much yay, level up love this channel