Create React App显示的是serviceWorker.js,而不是很多教程显示的registerServiceWorker [英] Create React App shows serviceWorker.js and not the registerServiceWorker that a lot of tutorials show
问题描述
当我想到我会使用Visual Studio Code来开始学习它等新的React JS应用程序时。我遇到了Microsoft网站 https://code.visualstudio.com/docs/nodejs/reactjs-tutorial 其中显示为
When I figured I would use Visual Studio Code to get a new React JS application started with learning it etc.. I ran across Microsoft site https://code.visualstudio.com/docs/nodejs/reactjs-tutorial In which this shows to
import registerServiceWorker from './registerServiceWorker';
同时,不存在,当我创建一个新的react应用时,它具有index.js
Meanwhile, there doesn't exist, when I create a new react app it has an index.js file with
import * as serviceWorker from './serviceWorker';
//
serviceWorker.unregister();
- 我不喜欢这么快地学习过时/过时的东西…有没有更好的最新地方来弄清楚我应该做些什么,以学习和有效地使用React JS?
- 似乎
registerServiceWorker( );
很常见,但这完全过时了吗? registerServiceWorker在React JS中做什么? - 我真的想真正地调用Web api的Restful终结点,在哪里找到最佳实践来实现此目的呢?
- I don't like learning something that is outdated /deprecated so quickly … Is there a much better up to date place to figure out what I am supposed to do to be learning and productively engaged with React JS?
- Seems that
registerServiceWorker();
was common but is this completely outdated? What does registerServiceWorker do in React JS? - I want to really just get into calling Restful endpoints of web api, what is a good place to do find best practices to do this?
推荐答案
serviceWorker支持是Create React App(CLI工具,而不是React本身)的一部分。它的官方文档很棒最新信息的地方:
The serviceWorker support is a part of Create React App (the CLI tool, not React itself). Its official docs are a great place for up-to-date information:
切换
serviceWorker.unregister()
转到serviceWorker.register()
将选择您使用服务工作者。
switching
serviceWorker.unregister()
toserviceWorker.register()
will opt you in to using the service worker.
<关于学习React,虽然有很多很棒的教程,但是您可以依靠 official教程以始终反映最新版本。
As for learning React, while there are a number of great tutorials out there, you can rely on the official tutorial to always reflect the latest version.
React只是一个视图库,并未规定发出HTTP请求的标准方法。您可以使用任何流行的请求库,也可以只使用普通的获取API ,React会很好玩。
React, being just a view library, doesn't prescribe a standard way to make HTTP requests. You can use any popular request library or just plain old Fetch API, and React will play nice with it.
这篇关于Create React App显示的是serviceWorker.js,而不是很多教程显示的registerServiceWorker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!