JS 模組化
import_export_module.exports 模組化
ES6 module
//------ lib.js ------
export sqrt = Math.sqrt;
//------ main.js ------
import sqrt from 'lib'; import * as lib from 'lib';export function addTodo(text) {
return {
type: 'ADD_TODO',
text
};
}
export function removeTodo(id) {
return {
type: 'REMOVE_TODO',
id
};
}CommonJS
使用import的格式
結論
使用require
有關react引入jsx
所以推薦使用ES6的import,下面hllo直接指到目標檔案的元件名稱,所以可以在一個jsx檔案內放多個元件
或是使用ES6 的exports 記得 require後加上 ".屬性"
Last updated