in Education by
I have a React User Profile page that retrieves User object from back-end. User profile object contains a lot of fields (about 30). I learnt that it is good practice in Typescript to create IUser interface and cast retrieved User object (JSON data) to IUser. User page is splitted to many subcomponents, and each component needs only some set of fields from User object (one component shows user general info, another shows user related post etc.). Since each of sub-component needs only some set of user fields, I forced to duplicate all required fields in Props of each sub-component. That seems to me like over-engineering and leads to a lot of code. Another options is to pass whole user object to each subcomponent. This way it will work, but that also smells bad, because I'm passing props to component that actually don't use them. What is elegant way to solve this problem? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
React is all about data flowing down in the component's tree. If you come to a point where state is fragmented you can always use redux. Some apps are too complex and nested to make good use of props. Take a look in hooks, they made possible to reuse stateful logic, but if what you want is really share state, use props or some state management tool like redux. Do not use Context in this case

Related questions

0 votes
    Check out this example code I saw: import * as React from 'react'; const Count: React.FunctionComponent ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I'm using an abstract superclass for some React components that share methods and some (but not all) props ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm using an abstract superclass for some React components that share methods and some (but not all) props ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    This is the example table that I want to do From the 'Yellow' highlight (row & column) color. I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    i'm messing with React and i was trying to make some transition between the router pages. Before using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    What is the difference between state and props in React?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    What are props in React?...
asked Jun 2, 2021 in Education by JackTerrance
0 votes
    Explain React state and props....
asked Dec 5, 2020 in Technology by JackTerrance
0 votes
    What are the different ways of passing parameters to the functions? Which to use when?...
asked Jan 18, 2021 in Technology by JackTerrance
+1 vote
    What are the different ways of passing parameters to the functions in C Programming? Which to use when?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    We begin with a computer implemented in single-cycle implementation. When the stages are split by functionality, the stages ... x 10= 1 Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    For example I have this 1 ['cancelled:', '7'] And I want to split to only get the integer value ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    For example I have this 1 ['cancelled:', '7'] And I want to split to only get the integer value ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    in split cell window we can specify the number of (i) Rows and cells (ii) Rows and Columns (iii) Columns and ... (iv) Tables and Cells Select the correct answer from above options...
asked Dec 5, 2021 in Education by JackTerrance
0 votes
    in split cell window we can specify the number of (i) Rows and cells (ii) Rows and Columns (iii) Columns and ... (iv) Tables and Cells Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
...