0

data is here subprojects={"RFv6bJMG2dmiBqWNZX8O":{"content":"this is ・・data"}}

console.log("subprojects=" + JSON.stringify(subprojects));
const SubList = ({ subprojects }) => {
if(subprojects){
  return (
    <div className="project-list section">
      {subprojects &&
        subprojects.map((subproject) => {
          return (
            <div>
              {subproject.id}
            </div>
          );
        })}
    </div>
  );}
  else{

The result is TypeError: subprojects.map is not a function

1

1 Answer 1

3

use Object.entries. Check MDN Docs.

      {
        Object.entries(subprojects).map(([key, val]) => {
          return (
            <div key={key}>
              {val.id}
            </div>
          );
        })}

Alternatively you can also use Object.values if you are not concerned about the keys

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

Comments

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.