At Codemancers, we believe every day is an opportunity to grow. This section is where our team shares bite-sized discoveries, technical breakthroughs and fascinating nuggets of wisdom we've stumbled upon in our work.
Aliases in Graphql. Let’s say we have a query that return us the cars Data. If we add both the queries, we will get an error. Fields "cars" conflict because they have differing arguments. Use different aliases on the fields to fetch both if this was intentional. UseCase Example: 👇This will throw error
It works because we are using aliases here. Aliases let us change the names of the data that is displayed in a query’s results. It is incredibly helpful when we need to fetch the same data using different filters.
Aliases in Graphql. Let’s say we have a query that return us the cars Data. If we add both the queries, we will get an error. Fields "cars" conflict because they have differing arguments. Use different aliases on the fields to fetch both if this was intentional. UseCase Example: 👇This will throw error
We have 7 different TypeScript utility types, like PickOmitPartialNonNullableReact.ComponentPropsReact.MouseEventHandler and special one React.PropsWithChildren
React's utility type PropsWithChildren enables components to take both props and child elements as input.
It is used in the definition of the component to identify the types of properties it can receive, including the children prop, which contains any elements contained within the component's JSX. In addition to children, it allows for the use of various props.
UseCase Example
Code
constTrack= ({ children }:PropsWithChildren) => {return ( {children} );};
If the expression index % 2 (modulus) evaluates to true, the class name col-span-4 will be added. The second className which is col-span-3 and it is added if the expression !(index % 2) evaluates to true. However the ! mark changes the Boolean to false
So class col-span-4 is added when the index is even, whereas the class col-span-3 is added when the index is odd.
Published
Author
Vinaysripath
Using Material UI to create an interface, use the icons, buttons, layouts, navigation and other MUI components. Using the sx prop to add css to individual components without using styled or tailwind classes. install MUI:
import { Box, IconButton, Paper, Typography } from "@mui/material";
simply use them like normal tags and add inline styles using the sx prop. The sx prop allows us to use a superset of css classes making it very intuitive to use.
Published
Author
Ayush Srivastava
System Analyst
React.Children
We can use the React.Children APIs to modify elements created by React before they’re rendered. It provides utilities for dealing with the this.props.children opaque data structure.
For example :-
Code
React.Children.count(children)
Returns the total number of components in children, equal to the number of times that a callback passed to map or forEach would be invoked
Published
Author
Vinaysripath
Using Material UI to create an interface, use the icons, buttons, layouts, navigation and other MUI components and adding styles using the sx prop.
Published
Author
Syed Sibtain
System Analyst
I discovered that manipulating the elements is possible with React.cloneElement() function. This can be used when a parent component wants to add or change the props of its children.
The function mentioned above makes a clone of the first parameter which is element and returns an element with the desired changes. We can further pass props to it as well.
Showing 49 to 51 of 83 results
Ready to Build Something Amazing?
Codemancers can bring your vision to life and help you achieve your goals