0

I'm trying to modularize my components into external files and import them into an index file, but I'm running into an error related to passing an array to an imported component. It doesn't appear to be handling this array in my modularized component and I'm wondering if it is an issue with my importation in my index file or with my component logic in the external file. Can anyone point me in the right direction?

index.js:

import React from 'react';
import fetch from 'node-fetch';
import ReactMarkdown from 'react-markdown';
import path from 'path';
import Comments from './comment/record-comment';

//Loop through JSON and create Record and Comment Container Component
const RecordFeed = props => {
    return (
        <div>
        { 
            props.records.map((record, index) => {
                return (
                    <RecordCard {...record} key={record.recordIdHash} user={props.user}>
                        { record.record_comments.map((comment, i) => 
                            <Comments {...comment} key={comment.recordCommentId} /> 
                        )}
                    </RecordCard>
                );
            })
        }
        </div>
    )
}

record-comment.js:

import React from 'react';

//Record Comment - Comment
const Comment = props => {
    return (
        <div>
            <h5>{props.user_id}</h5>
            <h4>{props.comment}</h4>
            <h3>{props.app_user.fullNameSlug}</h3>
        </div>
    )
}

//Record Comment - Container
export default class Comments extends React.Component {
    render() {
        return (
            <Comment />
        );
    }
}
3
  • Is there an error being logged? Commented Oct 23, 2017 at 11:46
  • Can't see you importing RecordCard Commented Oct 23, 2017 at 11:49
  • Please import RecordCard. Why you are using Comment and Comments . Both are same Commented Oct 23, 2017 at 11:54

1 Answer 1

1

Why do you have to export Comments component which does nothing, export just the Comment component as export default Comment. If in any case (which i can't think of) you do require to export Comments class, make sure you pass props to the child like -

export default class Comments extends React.Component { render() { return ( <Comment {...this.props} /> ); } }

Also, you don't seem to be importing your RecordCard component

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer. This was a template to see if the import was working. I plan on building on this foundation with more modularized elements, which is why I have the two components. Also, RecordCard is set elsewhere in the index.js file. I didn't think it was relevant to the question which is why I left it out of the code. Will I need to define props somewhere in the code you mentioned above?
No. The {...comments} and key props you have provided in index.js will be provided to the stateful Comments component as this.props.

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.