I am working on the ReactJS Project and I want to know if useEffect and useState in this case is necessary or if you have any logic explanation for this component:
I have component TableCellComponent that receive a value as props and this value can be primitive and non-primitive ,I use function to switch and then return the element. in this case is useEffect and useState is good solution or just using a function that render the element .
<code>const TableCellComponent = ({ value }: { value: any }) => {
const renderValue = (value: any) => {
switch (value) {
case typeof value === "number":
return <h1>number</h1>;
case typeof value === "object" && Array.isArray(value):
return <h1>Array</h1>;
}
};
return <td>{renderValue(value)}</td>;
};
export default TableCellComponent;
</code>
<code>const TableCellComponent = ({ value }: { value: any }) => {
const renderValue = (value: any) => {
switch (value) {
case typeof value === "number":
return <h1>number</h1>;
case typeof value === "object" && Array.isArray(value):
return <h1>Array</h1>;
}
};
return <td>{renderValue(value)}</td>;
};
export default TableCellComponent;
</code>
const TableCellComponent = ({ value }: { value: any }) => {
const renderValue = (value: any) => {
switch (value) {
case typeof value === "number":
return <h1>number</h1>;
case typeof value === "object" && Array.isArray(value):
return <h1>Array</h1>;
}
};
return <td>{renderValue(value)}</td>;
};
export default TableCellComponent;
New contributor
frioui meher is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.