{"id":1769,"date":"2019-03-04T18:05:58","date_gmt":"2019-03-04T18:05:58","guid":{"rendered":"https:\/\/www.codeastar.com\/?p=1769"},"modified":"2019-06-28T07:37:59","modified_gmt":"2019-06-28T07:37:59","slug":"react-frontend-weather-forecast-2","status":"publish","type":"post","link":"https:\/\/www.codeastar.com\/react-frontend-weather-forecast-2\/","title":{"rendered":"React Frontend and Flask Backend for Weather Forecast \u2013 Part 2"},"content":{"rendered":"\n
From our last post, “Flask Backend and React Frontend for Weather Forecast \u2013 Part 1<\/a>“, we built our magic user, RESTful API as the backend module with Flask. This time, we are going to build our sword swinger, who always deals with challenges at the front line. Before we go further, let’s have a little rewind. Do you remember why we separate web app into backend and frontend modules? Yes, I know you can answer it (don’t you? :]] ). Because of utilizing both modules to their max capability. From our 2019 Top Programming Languages<\/a> post, we mentioned that frontend languages are much stronger nowadays and hot in job market. Although we have focused on Python backend mostly in this blog, it is a valuable experience to taste the frontend languages. So, let’s enter our new page of frontend languages, and code our React Frontend for the EZ Weather Forecast (EZW) project.<\/p>\n\n\n\n\n\n\n\n Yes, why React? Since there are several frontend languages, like Angular and Vue.js. Our reasons of choosing React<\/a> are: ease of use, popularity and the size of community. Actually, those are also the reasons we pick Python as our major language as well. It will be easier if we try something new which is similar to something we are familiar with.<\/p>\n\n\n\n Oh wait, you don’t have any React experience? No problem, then we go for it step-by-step. First things first, even though we always use the term “frontend languages”, they are all JavaScript framework or library. In order to write our frontend (JavaScript) module, we need a JavaScript runtime — Node.js<\/a>. Go to download the latest stable version and run following command to start our first ever React frontend: <\/p>\n\n\n\n Thus we have started our first ever React frontend module on http:\/\/localhost:3000. We have prepared our development environment, so it is time to update the generic boilerplate to our actual EZW frontend.<\/p>\n\n\n\n Before we start our coding, let’s define our expected outcome. On our previous EZW single module setup<\/a>, we have following user interface: <\/p>\n\n\n\nWhy React Frontend? <\/h3>\n\n\n\n
$npx create-react-app ezw_react\n$cd ezw_react\n$npm start<\/code><\/pre>\n\n\n\n
EZW Frontend with React<\/h3>\n\n\n\n