创建react应用程序_通过构建电影搜索应用程序在1小时内了解React

创建react应用程序

If you've been meaning to learn React but are unsure of where to start, Scrimba's brand new Build a Movie Search App course is perfect for you!

如果您一直想学习React,但是不确定从哪里开始,那么Scrimba全新的Build a Movie Search App课程非常适合您!

In this course, you'll be guided through the app's creation from start to finish in just one hour. And you'll work through interactive challenges along the way that help you gain the muscle memory you need to become an effective React developer.

在本课程中,您将在一个小时内从头到尾指导您完成应用的创建过程。 然后,您将通过互动挑战的方式来工作,以帮助您获得成为一名有效的React开发人员所需的肌肉记忆。

为什么要学习React? (Why learn React?)

React is the world's most popular front-end framework. As the docs state, React makes it painless to create interactive UIs and more predictable code which is easier to debug. With React, you can produce complex UIs through constructing reusable components that manage their own state.

React是世界上最受欢迎的前端框架。 正如文档所述 ,React使创建交互式UI和更可预测的代码变得更加轻松,并且更易于调试。 使用React,您可以通过构建可管理其自身状态的可重用组件来生成复杂的UI。

这门课程做什么? (What does this course do?)

Styled movie cards

This learning journey takes you through 11 interactive screencasts, showing you the following core concepts of modern React:

本学习之旅将带您浏览11个交互式截屏视频,向您展示现代React的以下核心概念:

  • How to get an API key

    如何获得API密钥
  • Adding base styles

    添加基本​​样式
  • Creating and styling components

    创建和样式化组件
  • Creating functions

    创建功能
  • Managing state using hooks

    使用挂钩管理状态
  • Displaying information

    显示信息
  • Creating and styling cards

    创建和样式卡片

老师介绍 (Intro to the teacher)

This tutorial is led by James Q. Quick, a full-stack Web Developer who regularly speaks at community events and participates in Hackathons. He also runs a YouTube channel teaching web development. His motto 'Learn. Build. Teach.' makes him the perfect teacher for this practical course.

本教程由James Q. Quick领导,他是全栈Web开发人员,他定期在社区活动中演讲并参加Hackathons。 他还经营一个YouTube频道,教授网络开发。 他的座右铭是“学习。 建立。 教。' 使他成为该实践课程的完美老师。

先决条件 (Prerequisites)

To study this course effectively, you should have basic knowledge of HTML, CSS, and JavaScript. You'll also find it useful to have seen some React code before, but it's not a must-have.

为了有效地学习本课程,您应该具有HTML,CSS和JavaScript的基本知识。 您还会发现之前看过一些React代码很有用,但这不是必须的。

If you need a bit more background knowledge, take a look at these fantastic free Scrimba courses:

如果您需要更多的背景知识,请查看这些出色的免费Scrimba课程:

  • HTML and CSS

    HTML和CSS

  • Javascript

    Java脚本

If you're ready to hit the ground running with React, let's get started!

如果您准备使用React运行,请开始吧!

课程介绍 (Course Introduction)

Build a Movie Search App Course front title slide

In the first scrim, James runs us through a few of the key features of the app we'll be building and gives us a quick rundown of how the app works. Lastly, James introduces us to the API we'll use - themoviedb.org.

在第一个讲义中 ,James为我们介绍了我们将要构建的应用程序的一些关键功能,并为我们提供了该应用程序的工作原理的简要概述。 最后,James向我们介绍了我们将使用的API-themoviedb.org 。

如何获取电影DB API密钥 (How to Get Your Movie DB API Key)

Generating a MovieDB API key

In this short cast, James gives us the lowdown on how to get a Movie DB API Key by signing up with a free account. This is super straightforward and takes just a few minutes. Click the image above to access the course.

在这个简短的节目中,James向我们介绍了如何通过注册免费帐户来获取Movie DB API密钥。 这非常简单,只需几分钟。 单击上面的图像访问课程。

将基本样式添加到您的应用 (Add Base Styles to Your App)

Next up, James shows us the basic React application he has instantiated for us:

接下来 ,James向我们展示了他为我们实例化的基本React应用程序:

import React from "react";
import ReactDOM from "react-dom";class Main extends React.Component {render() {return <h1>Hello world!</h1>;}
}ReactDOM.render(<Main />, document.getElementById("root"));

We then add some base styles to our style.css file including margins and padding, title styles and, the Holy Grail of CSS - centering the app's contents. Click here to check out the styles for yourself.

然后,我们将一些基本样式添加到我们的style.css文件中,包括页边距和填充,标题样式以及CSS的圣杯-将应用程序的内容居中。 单击此处自行检查样式。

创建您的第一个组件 (Create Your First Component)

Our first React app in action

In this scrim, we have our first challenge - to create a React component. James uses a test.js file to give us a brief preview of what's needed before breaking down the task into manageable chunks:

在这个稀松布里 ,我们面临的第一个挑战-创建一个React组件。 James使用test.js文件向我们简要预览了将任务分解为可管理的块之前所需的内容:

//to create the SearchMovies component //form with a class of form //label with
htmlFor="query" and a class of Label //input of type text with a name of "query"
and a placeholder //button class of button and a type of submit

Click through to the link or image above to get your hands dirty and give the challenge a try.

单击以查看上面的链接或图像,以使您的双手变脏并尝试挑战。

设置搜索电影组件的样式 (Style the Search Movies Component)

Our first React app with styles added

Next up, it's time to style our new app. James suggests some styles for our <form>, <label>, <input> and <button> and adds a media query to adjust the styles on larger screens:

接下来 ,是时候设计我们的新应用程序了。 James为我们的<form><label><input><button>建议了一些样式,并添加了媒体查询来调整大屏幕上的样式:

@media (min-width: 786px) {.form {grid-template-columns: auto 1fr auto;grid-gap: 1rem;align-items: center;}.input {margin-bottom: 0;}
}

Don't forget that Scrimba is fully interactive, so you can be as creative as you like with the styles - these ideas are just some possibilities.

不要忘记Scrimba是完全互动的,所以您可以根据自己的喜好使用样式-这些想法只是其中的一种。

创建搜索电影功能 (Create the Search Movies Function)

export default function SearchMovies(){const searchMovies = async (e) => {e.preventDefault();const query = "Jurassic Park";const url = `https://api.themoviedb.org/3/search/movie?api_key=5dcf7f28a88be0edc01bbbde06f024ab&language=en-US&query=${query}&page=1&include_adult=false`;try {const res = await fetch(url);const data  = await res.json();console.log(data);}catch(err){console.error(err);}}

In this screencast, we create an async function that will use the Fetch API to retrieve the movie information from the Movie DB API. Hit the link to see how it's done.

在此截屏视频中 ,我们创建一个异步函数,该函数将使用Fetch API从Movie DB API中检索电影信息。 点击链接以了解操作方法。

使用React useState Hook管理状态 (Manage State with React useState Hook)

In this scrim, James shows us how to use state to track the user's query with the useState hook:

在此稀松布中 ,James向我们展示了如何使用useState钩子使用state来跟踪用户的查询:

const [query, setQuery] = useState("");

Next, we set the onChange on our <input> to bind it to that state:

接下来,我们在<input>上设置onChange以将其绑定到该状态:

<inputclassName="input"type="text"name="query"placeholder="i.e. Jurassic Park"value={query}onChange={(e) => setQuery(e.target.value)}
/>

Then it's time for our second challenge - to create the state for movie information and update that state as appropriate. Hop on over to the tutorial to try it out.

然后是第二个挑战的时候了-为电影信息创建状态并适当地更新该状态。 跳至本教程进行尝试。

显示电影信息 (Display Movie Information)

App displaying movie info

Now that we can search for our movies, it's time to display the information to the user. Click the link or image to see how it's done!

现在我们可以搜索电影了,现在该向用户显示信息了。 单击链接或图像以查看完成情况!

设置电影卡的样式 (Style the Movie Cards)

Styled movie cards

Next up, James shows us how to style our movie cards to create an attractive, user-friendly app. We start with our card container <div> :

接下来 ,James向我们展示了如何为电影卡设置样式,以创建有吸引力的,用户友好的应用程序。 我们从卡片容器<div>

.card {padding: 2rem 4rem;border-radius: 10px;box-shadow: 1px 1px 5px rgba(0,0,0,0.25);margin-bottom: 2rem;background-color: white;
}

With that done, we move onto our titles and images. Click the link or image above to get the lowdown.

完成后,我们进入标题和图像。 单击上面的链接或图像以获取下拉列表。

创建电影卡组件(挑战) (Create the Movie Card Component (Challenge))

Our final task is to create a separate component to display the movie card. This ensures maintainability should our project grow, and is a good habit to get into in preparation for bigger projects.

我们的最终任务是创建一个单独的组件来显示电影卡。 这样可以确保在我们的项目增长时具有可维护性,并且是养成准备更大项目的好习惯。

In true Scrimba style, James presents this challenge and then walks us through his solution. Head over to the cast now to try for yourself. Note: Props are needed for this, but James gives a quick how-to in the task explanation.

James以真正的Scrimba风格提出了这一挑战,然后带领我们完成了他的解决方案。 立即前往演员表尝试一下。 注意:为此需要道具,但是James在任务说明中提供了快速的操作方法。

结语 (Wrap up)

Congratulations on completing the Movie Search app! You now know how to build a fully functional app using core React concepts including functional components, hooks, fetch requests, styling, and reusable components.

恭喜您完成了电影搜索应用程序! 您现在知道如何使用React的核心概念(包括功能组件,挂钩,获取请求,样式和可重用组件)构建功能全面的应用程序。

I hope that you gained a lot from this course and feel inspired to continue your learning journey. To find out more about React, head over to Scrimba's free, six-hour Learn React for Free course.

我希望您从本课程中学到了很多东西,并感到鼓舞继续学习。 要了解有关React的更多信息,请前往Scrimba的免费六小时免费学习React免费课程。

After that, why not check out all the other great courses available over on Scrimba to see where you'll go next?

之后,为什么不检查一下Scrimba上所有其他可用的优秀课程,以了解下一步的发展方向呢?

Wherever your journey takes you, happy coding :)

无论您走到哪里,都可以享受快乐的编码:)

翻译自: https://www.freecodecamp.org/news/learn-react-in-1-hour-by-building-a-movie-search-app/

创建react应用程序

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/390241.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

GeoServer自动发布地图服务

1 NetCDF气象文件自动发布案例 GeoServer是一个地理服务器&#xff0c;提供了管理页面进行服务发布&#xff0c;样式&#xff0c;切片&#xff0c;图层预览等一系列操作&#xff0c;但是手动进行页面配置有时并不满足业务需求&#xff0c;所以GeoServer同时提供了丰富的rest接口…

selenium+ python自动化--断言assertpy

前言&#xff1a; 在对登录验证时&#xff0c;不知道为何原因用unittest的断言不成功&#xff0c;就在网上发现这个assertpy&#xff0c;因此做个笔记 准备&#xff1a; pip install assertypy 例子&#xff1a; 1 from assertpy import assert_that2 3 4 def check_login():5 …

11. 盛最多水的容器

11. 盛最多水的容器 给你 n 个非负整数 a1&#xff0c;a2&#xff0c;…&#xff0c;an&#xff0c;每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线&#xff0c;垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0) 。找出其中的两条线&#xff0c;使得它们与 x 轴共同构…

深入理解ES6 pdf

下载地址&#xff1a;网盘下载目录 第1章 块级作用域绑定 1var声明及变量提升&#xff08;Hoisting&#xff09;机制 1块级声明 3-- let声明 3-- 禁止重声明 4-- const声明 4-- 临时死区&#xff08;Temporal Dead Zone&#xff09; 6循环中的块作用域绑定 7-- 循环中的函…

MyBatis之输入与输出(resultType、resultMap)映射

2019独角兽企业重金招聘Python工程师标准>>> 在MyBatis中&#xff0c;我们通过parameterType完成输入映射(指将值映射到sql语句的占位符中&#xff0c;值的类型与dao层响应方法的参数类型一致)&#xff0c;通过resultType完成输出映射(从数据库中输出&#xff0c;通…

2021-08-25556. 下一个更大元素 III

556. 下一个更大元素 III 给你一个正整数 n &#xff0c;请你找出符合条件的最小整数&#xff0c;其由重新排列 n 中存在的每位数字组成&#xff0c;并且其值大于 n 。如果不存在这样的正整数&#xff0c;则返回 -1 。 注意 &#xff0c;返回的整数应当是一个 32 位整数 &…

gradle tool升级到3.0注意事项

Gradle版本升级 其实当AS升级到3.0之后&#xff0c;Gradle Plugin和Gradle不升级也是可以继续使用的&#xff0c;但很多新的特性如&#xff1a;Java8支持、新的依赖匹配机制、AAPT2等新功能都无法正常使用。 Gradle Plugin升级到3.0.0及以上&#xff0c;修改project/build.grad…

如何使用React,TypeScript和React测试库创建出色的用户体验

Im always willing to learn, no matter how much I know. As a software engineer, my thirst for knowledge has increased a lot. I know that I have a lot of things to learn daily.无论我知道多少&#xff0c;我总是愿意学习。 作为软件工程师&#xff0c;我对知识的渴望…

PowerDesigner常用设置

2019独角兽企业重金招聘Python工程师标准>>> 使用powerdesigner进行数据库设计确实方便&#xff0c;以下是一些常用的设置 附加&#xff1a;工具栏不见了 调色板(Palette)快捷工具栏不见了 PowerDesigner 快捷工具栏 palette 不见了&#xff0c;怎么重新打开&#x…

bzoj5090[lydsy11月赛]组题

裸的01分数规划,二分答案,没了. #include<cstdio> #include<algorithm> using namespace std; const int maxn100005; int a[maxn]; double b[maxn]; double c[maxn]; typedef long long ll; ll gcd(ll a,ll b){return (b0)?a:gcd(b,a%b); } int main(){int n,k;s…

797. 所有可能的路径

797. 所有可能的路径 给你一个有 n 个节点的 有向无环图&#xff08;DAG&#xff09;&#xff0c;请你找出所有从节点 0 到节点 n-1 的路径并输出&#xff08;不要求按特定顺序&#xff09; 二维数组的第 i 个数组中的单元都表示有向图中 i 号节点所能到达的下一些节点&#…

深入框架本源系列 —— Virtual Dom

该系列会逐步更新&#xff0c;完整的讲解目前主流框架中底层相通的技术&#xff0c;接下来的代码内容都会更新在 这里 为什么需要 Virtual Dom 众所周知&#xff0c;操作 DOM 是很耗费性能的一件事情&#xff0c;既然如此&#xff0c;我们可以考虑通过 JS 对象来模拟 DOM 对象&…

网络工程师常备工具_网络安全工程师应该知道的10种工具

网络工程师常备工具If youre a penetration tester, there are numerous tools you can use to help you accomplish your goals. 如果您是渗透测试人员&#xff0c;则可以使用许多工具来帮助您实现目标。 From scanning to post-exploitation, here are ten tools you must k…

configure: error: You need a C++ compiler for C++ support.

安装pcre包的时候提示缺少c编译器 报错信息如下&#xff1a; configure: error: You need a C compiler for C support. 解决办法&#xff0c;使用yum安装&#xff1a;yum -y install gcc-c 转载于:https://www.cnblogs.com/mkl34367803/p/8428264.html

程序编写经验教训_编写您永远都不会忘记的有效绩效评估的经验教训。

程序编写经验教训This article is intended for two audiences: people who need to write self-evaluations, and people who need to provide feedback to their colleagues. 本文面向两个受众&#xff1a;需要编写自我评估的人员和需要向同事提供反馈的人员。 For the purp…

删除文件及文件夹命令

方法一&#xff1a; echo off ::演示&#xff1a;删除指定路径下指定天数之前&#xff08;以文件的最后修改日期为准&#xff09;的文件。 ::如果演示结果无误&#xff0c;把del前面的echo去掉&#xff0c;即可实现真正删除。 ::本例需要Win2003/Vista/Win7系统自带的forfiles命…

BZOJ 3527: [ZJOI2014]力(FFT)

题意 给出\(n\)个数\(q_i\),给出\(Fj\)的定义如下&#xff1a; \[F_j\sum \limits _ {i < j} \frac{q_iq_j}{(i-j)^2}-\sum \limits _{i >j} \frac{q_iq_j}{(i-j)^2}.\] 令\(E_iF_i/q_i\)&#xff0c;求\(E_i\). 题解 一开始没发现求\(E_i\)... 其实题目还更容易想了... …

c# 实现刷卡_如何在RecyclerView中实现“刷卡选项”

c# 实现刷卡Lets say a user of your site wants to edit a list item without opening the item and looking for editing options. If you can enable this functionality, it gives that user a good User Experience. 假设您网站的用户想要在不打开列表项并寻找编辑选项的情…

批处理命令无法连续执行

如题&#xff0c;博主一开始的批处理命令是这样的&#xff1a; cd node_modules cd heapdump node-gyp rebuild cd .. cd v8-profiler-node8 node-pre-gyp rebuild cd .. cd utf-8-validate node-gyp rebuild cd .. cd bufferutil node-gyp rebuild pause执行结果&#xff1…

sql语句中的in用法示例_示例中JavaScript in操作符

sql语句中的in用法示例One of the first topics you’ll come across when learning JavaScript (or any other programming language) are operators. 学习JavaScript(或任何其他编程语言)时遇到的第一个主题之一是运算符。 The most common operators are the arithmetic, l…