Feb 24 2024
熱飯班長 -
當useEffect遇到函數依賴
下面的代碼實現了一個簡易的登錄功能(為了減少代碼量,去掉了密碼)。
import React, { useState } from 'react';
const api = {
login(username) {
console.log('username', username);
},
};
function Login() {
const [username, setU
react
,
react-hooks
Feb 20 2024
熱飯班長 -
ES modules的導出方式
Named Exports
// module1.js
export const name = 'Ben';
// app.js
import { name } from './module1.js'
console.log(name);
// Ben
// module1.js
const name = 'Ben';
export { name };
// app.js
import { n
export
,
import
Feb 17 2024
熱飯班長 -
package.json配置項記錄
bin
{
"bin": {
"gh-pages": "bin/gh-pages.js",
}
}
包裏面的bin字段相當於在説:“嗨npm,如果待會兒有人執行gh-pages這個命令,就去我目錄下找bin/gh-pages.js這個文件”。
scripts
{
"dependencies": {
"gh-pages": "^6.1.1"
},
"scripts
package.json
Feb 17 2024
熱飯班長 -
craco使用問題記錄
如何配置less?
// craco.config.js
const CracoLessPlugin = require('craco-less');
module.exports = {
plugins: [
{
plugin: CracoLessPlugin,
options: {
cssLoaderOptions: {
create-react-app
Feb 16 2024
熱飯班長 -
對象方法用途記錄
entries
注意:這是一個靜態方法而非原型方法。
用途:需要將對象轉換為數組進行處理時。
該方法接受一個對象,然後返回一個數組,該數組的每個元素為一組對象的鍵名和鍵值。
const arr = Object.entries({name1: 'tom', name2: 'lily'})
console.log('arr', arr)
// [['name1', 'tom'], ['name
object
,
Javascript