官术网_书友最值得收藏!

Adding Bootstrap support

One of the things we need to do with our application is bring in support for Bootstrap. This is not something that is provided out of the box with React, so we need to add this capacity using other packages:

  1. Install Bootstrap as follows:
npm install --save bootstrap

  1. With this in place, we are now free to use a React-ready Bootstrap component. We are going to use the reactstrap package because this package targets Bootstrap 4 in a React-friendly fashion:
npm install --save reactstrap react react-dom
  1. reactstrap is not a TypeScript component, so we need to install the DefinitelyTyped definition for this and for Bootstrap:
npm install --save @types/reactstrap
npm install --save @types/bootstrap
  1. With this in place, we can now add the Bootstrap CSS files. To do this, we are going to update the index.tsx file by adding a reference to our locally installed Bootstrap CSS file, by adding the following import to the very top of the file:
import "bootstrap/dist/css/bootstrap.min.css";
Here, we are using the local Bootstrap file for convenience. As we discussed in Chapter 1, Advanced TypeScript Features, we want to change this to use a CDN source for the production version of this application.
  1. To tidy up, remove the following line from src/index.tsx and then remove the matching .css file from the disk:
import './index.css'
主站蜘蛛池模板: 咸宁市| 瑞昌市| 深水埗区| 大宁县| 台中县| 陕西省| 灌阳县| 青田县| 阳曲县| 尖扎县| 株洲市| 克什克腾旗| 甘肃省| 汤原县| 全州县| 攀枝花市| 同江市| 东山县| 马尔康县| 岚皋县| 巴彦淖尔市| 江安县| 新竹县| 泾阳县| 巨鹿县| 抚松县| 巫山县| 房山区| 陵川县| 舒兰市| 集安市| 张家口市| 山阴县| 南汇区| 本溪市| 马公市| 兴宁市| 资兴市| 青浦区| 临潭县| 延庆县|