79433275

Date: 2025-02-12 13:44:30
Score: 1
Natty:
Report link

why default props is not being set even parent component not passing or that prop even being not set by parent . only working when parent passing data. import React, { Fragment } from "react";

import PropTypes from "prop-types";

const Props1= (prop) => {

  return (
    <Fragment>
      <br />
      I am child {prop.name}
      <br />
      {prop.children} {/* Render children */}
    </Fragment>
  );
}



// Set default value for name if it's not passed
Props1.defaultProps = {
  name: "rajuuuu", // Default value for 'name'
};

export default Props1; 
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Starts with a question (0.5): why
  • Low reputation (1):
Posted by: vinod raj dharamkar