从另一个文件夹导入react组件

时间:2020-05-16 08:49:23

标签: reactjs

我有一个文件夹组件。

组件文件夹中有OutlinedField。

在App.js中,我做了import OutlinedField from "./../component";,但失败了。

我的代码在https://codesandbox.io/s/eloquent-cloud-ngk6u?file=/src/App.js

enter image description here

1 个答案:

答案 0 :(得分:1)

由于component文件夹与app.js文件位于同一目录中,因此只需添加
import OutlinedField from './component/OutlinedField'

App.js

import React from "react";
import "./styles.css";
import OutlinedField from './component/OutlinedField';
export default function App() {
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>
    </div>
  );
}