admin管理员组文章数量:1291085
I tried to import ResponseForm but the error
Failed to pile. ./src/ponents/projects/ProjectDetails.js Attempted import error: 'ResponseForm' is not exported from './ResponseForm'.
happens.
ResponseForm ponent actually exists. The path seems to be correct. How should I fix it? Why is import error occuring?
import {Component} from 'react'
import {connect} from 'react-redux'
import {createProject} from '../../store/actions/projectActions'
import { Redirect } from 'react-router-dom'
const ResponseForm = () => {
state = {
content: ''
}
handleChange = (e) => {
this.setState({
[e.target.id]: e.target.value
})
}
handleSubmit = (e) => {
e.preventDefault()
this.props.createProject(this.state)
}
return (
<div className="container">
<form onSubmit={handleSubmit} className="white">
<h5 className="grey-text text-darken-3">KAITO</h5>
<div className="input-field">
<button className="btn pink lighten-1 z-depth-0">TEST</button>
</div>
</form>
</div>
)
}
export default ResponseForm;
import { connect } from "react-redux";
import { firestoreConnect,useFirestoreConnect } from "react-redux-firebase";
import { pose } from "redux";
import { ResponseForm } from "./ResponseForm";
const ProjectDetails = (props) => {
const { project } = props;
if (project) {
return (
<div className="container section project-details">
<div className="card z-depth-0">
<div className="card-content">
<span className="card-title">{project.title}</span>
<p>{project.content}</p>
</div>
<ResponseForm />
<div className="project-list section"></div>
</div>
</div>
);
} else {
return (
<div className="container center">
<p>Loaging project...</p>
</div>
);
}
};
I tried to import ResponseForm but the error
Failed to pile. ./src/ponents/projects/ProjectDetails.js Attempted import error: 'ResponseForm' is not exported from './ResponseForm'.
happens.
ResponseForm ponent actually exists. The path seems to be correct. How should I fix it? Why is import error occuring?
import {Component} from 'react'
import {connect} from 'react-redux'
import {createProject} from '../../store/actions/projectActions'
import { Redirect } from 'react-router-dom'
const ResponseForm = () => {
state = {
content: ''
}
handleChange = (e) => {
this.setState({
[e.target.id]: e.target.value
})
}
handleSubmit = (e) => {
e.preventDefault()
this.props.createProject(this.state)
}
return (
<div className="container">
<form onSubmit={handleSubmit} className="white">
<h5 className="grey-text text-darken-3">KAITO</h5>
<div className="input-field">
<button className="btn pink lighten-1 z-depth-0">TEST</button>
</div>
</form>
</div>
)
}
export default ResponseForm;
import { connect } from "react-redux";
import { firestoreConnect,useFirestoreConnect } from "react-redux-firebase";
import { pose } from "redux";
import { ResponseForm } from "./ResponseForm";
const ProjectDetails = (props) => {
const { project } = props;
if (project) {
return (
<div className="container section project-details">
<div className="card z-depth-0">
<div className="card-content">
<span className="card-title">{project.title}</span>
<p>{project.content}</p>
</div>
<ResponseForm />
<div className="project-list section"></div>
</div>
</div>
);
} else {
return (
<div className="container center">
<p>Loaging project...</p>
</div>
);
}
};
Share
Improve this question
edited Mar 8, 2021 at 8:52
Hkachhia
4,5397 gold badges44 silver badges78 bronze badges
asked Mar 8, 2021 at 8:50
user14232549user14232549
4137 silver badges19 bronze badges
3 Answers
Reset to default 7Because you're using export default
, your import statement should look like this:
import ResponseForm from "./ResponseForm";
(no curly braces)
Alternatively, you could change your first file to this:
export const ResponseForm = () => {
and remove the export default
line at the end. Then, you could keep your current import syntax.
This is because you are exporting ResponseFrom as default and try to import using {}
which need to like this
import ResponseForm from "./ResponseForm";
instead of
import { ResponseForm } from "./ResponseForm";
in ProjectDetails
Answer
Response form is the default export:
export default ResponseForm;
You should import it like this:
import ResponseForm from "./ResponseForm";
Using non default exports
If you want to avoid making it the default export you can do this:
import {Component} from 'react'
import {connect} from 'react-redux'
import {createProject} from '../../store/actions/projectActions'
import { Redirect } from 'react-router-dom'
export const ResponseForm = () => {
state = {
content: ''
}
handleChange = (e) => {
this.setState({
[e.target.id]: e.target.value
})
}
handleSubmit = (e) => {
e.preventDefault()
this.props.createProject(this.state)
}
return (
<div className="container">
<form onSubmit={handleSubmit} className="white">
<h5 className="grey-text text-darken-3">KAITO</h5>
<div className="input-field">
<button className="btn pink lighten-1 z-depth-0">TEST</button>
</div>
</form>
</div>
)
}
And import it as above:
import { ResponseForm } from "./ResponseForm";
本文标签:
版权声明:本文标题:javascript - How should I solve "Attempted import error: 'Component' is not exported from '.Com 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741516396a2382914.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论