0

The following component is meant to represent a table with lines that each contain line numbers, text, and some structure.

The variable text is meant to take a list of objects. Each object may represent a single line, or it may represent a "subproof" which would be another table containing lines and so on. It is then supposed to map each line to a Line component, and each subproof to a Subproof component.

import Line from './Line'

const Subproof = ({proof_lines, depth}) => {
    const text = proof_lines.map( (line, index) => (
      console.log(index),
      line.hasOwnProperty("statement") 
        ? <Line 
            key={index} 
            line_num={index} 
            depth={depth} 
            statement={line.statement} 
            reason={line.reason} 
          /> 
        : <div key={index}>False</div>
    ));
  return (
    <div className="subproof">
      {text}
    </div>
  );
};

export default Subproof;

When I log the index, it works exactly as I expect: It tells me the index of the object in the list. But, when I go over to the Line object, where I've passed this in as a prop ...

const Line = (line_num, depth, statement, reason) => {
  return <div className="Line">
      {console.log(line_num)}
      <div className="Line_num">{line.num}</div>
  </div>;
};

export default Line;

This gets logged not as the index but as the object itself. Naturally that then causes an error when it tries to build the page because what I'm inserting into the HTML is an object, rather than what I intended which was a simple number.

1 Answer 1

1

prop of a component needs to be an object:

const Line = ({line_num, depth, statement, reason}) => {
  ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, and I just made that same mistake yesterday. I'll drill it in my head eventually, but sorry for the dumb question! And thanks for the answer!

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.