0

I am pretty new to React Framework, What I am trying to do is that from my Dishdetail.js I am calling the <Commentform /> component so that it displays me a button Submit Comment button. Dishdetail.js is completely fine so I submitted only part of my code from Dishdetail.js so that it doesn't look cluttered. The problem is for my CommentformComponent.js file component I am getting import errors saying

./src/Components/DishdetailComponent.jsAttempted import error: 'Commentform' is not exported from './CommentformComponent'.

I did write my export from my CommentforComponent.js and here is my full code for CommenforComponent.js file

///THIS IS MY Dishdetail.js file
import {Commentform} from './CommentformComponent';

function RenderComments({comments}){  
        if(comments!=null){           
            const dishComments=comments.map( (comment) => { 
            return( 
                  <ul key={comment.id} className = "list-unstyled">
                 <p>{comment.comment}</p>
                 <p>--{comment.author},{new Intl.DateTimeFormat('en-US', { year: 'numeric',month: 'short', day: '2-digit'}).format(new Date(Date.parse(comment.date)))} </p>
                 </ul>
                  );

        return(
            <div>
                <h4>Comments</h4>
                {dishComments}
                <Commentform />
            </div>
        )
    }
        else{
            return(
                <div></div>
            );
        }
    }
///CommentformComponent.js file
import React, {Component} from 'react';
import {  Button  } from 'reactstrap';
import {Link} from 'react-router-dom';
import {Control,LocalForm,Errors} from 'react-redux-form';

class Commentform extends Component{       
    render(){      
        return(

            <Button type="submit" color="outline-dark">
                <span className="fa fa-pencil fa-lg"></span>Submit Comment
            </Button>
        );
    }

}
export default Commentform;

1 Answer 1

1

Just do:

import Commentform from './CommentformComponent';

Importing a component depends on how you export it:

export default Commentform;
import Commentform from './CommentformComponent';

or

export Commentform;
import { Commentform } from './CommentformComponent';
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much it worked....But why did we omit the curly braces from Commentform?
If you export as default, no curly braces. You use curly braces when you export several components from the same file and without using default

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.