import, export
Hello Reactを表示するようまでをまとめています。
下の表示がディレクトリの構成です。
├── src
│ ├── App.js
│ ├── contexts
│ │ └── hello.js
App.js
import { Hello } from './contexts/hello.js';
function App() {
return (
<Hello />
);
}
import { Hello } from './contexts/hello.js';
App.jsでHello関数を呼び出してretunでHello関数を表示しています。
hello.js
export const Hello = () => {
return (
<div>Hello React</div>
)
}
hello.js
はexport
でHello関数を他のファイルでも使えるように設定しています。