Bài 3: Cấu hình scss vào dự án

1. Tạo file GlobalStyles component 1.1 Tạo file src/components/GlobalStyles/index.tsx import './GlobalStyles.scss'; type Props = { children: JSX.Element; }; function GlobalStyles({ children }: Props) { return children; } export default GlobalStyles; 1.2 Tạo file src/components/GlobalStyles/GlobalStyles.scss @import 'normalize.css'; @import url('https://fonts.googleapis.com/css2?family=Roboto:[email protected];400;500;700;900&display=swap'); :root { --primary: #fe2c55; } html { font-size: 62.5%; } body { font-family: 'Roboto', sans-serif; font-size: 1.6rem;

1. Tạo file GlobalStyles component

1.1 Tạo file src/components/GlobalStyles/index.tsx

import './GlobalStyles.scss';

type Props = {
    children: JSX.Element;
};

function GlobalStyles({ children }: Props) {
    return children;
}

export default GlobalStyles;

1.2 Tạo file src/components/GlobalStyles/GlobalStyles.scss

@import 'normalize.css';
@import url('https://fonts.googleapis.com/css2?family=Roboto:[email protected];400;500;700;900&display=swap');

:root {
    --primary: #fe2c55;
}

html {
    font-size: 62.5%;
}

body {
    font-family: 'Roboto', sans-serif;
    font-size: 1.6rem;
    line-height: 1.5;
    text-rendering: optimizespeed;
}

2. Cài thư viện reset css và scss

yarn add --save normalize.css
yarn add sass

3. Sửa lại file index.tsx

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from '~/App';
import GlobalStyles from '~/components/GlobalStyles';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
    <React.StrictMode>
        <GlobalStyles>
            <App />
        </GlobalStyles>
    </React.StrictMode>,
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

4. Xoá các file ko cần thiết như index.css. logo, app.css

Nguồn: viblo.asia

Bài viết liên quan

Cấu hình Prisma v7 Với Nest.js Mới nhất

Setup Prisma v7 trong Nest.js Bài viết dành cho ai mới học Nest.js và chọn prisma làm OR

Tấn Công Ứng Dụng Web: Mối Đe Dọa Hàng Đầu – Phần 2

viết lại nội dung này ” Phát hiện các cuộc tấn công Cross Site Scripting (XSS)

AI Chatbot 2025: Xu Hướng Tất Yếu Cho Doanh Nghiệp Dẫn Đầu

Giới thiệu AI chatbots đã trải qua một hành trình đáng kể, từ những công cụ t

Tấn Công Ứng Dụng Web: Mối Đe Dọa Hàng Đầu – Phần 1

Tấn công web là gì? Ứng dụng web là các ứng dụng cung cấp dịch vụ cho người