TILs - Fueling Curiosity, One Insight at a Time

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.

Published
Author
user-image
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
user-image
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
user-image
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.

React.cloneElement(element, [props], [...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.
Published
Author
user-image
Ayush Srivastava
System Analyst
CLS i.e Cumulative Layout Shift a metric used to quantify the stability of the content on a website when it loads. Normally a layout Shift occurs whenever any element on the web page changes it position unexpectedly.

Major Reason that constitutes to CLS are :-
1. Images without dimensions
2. Dynamically Injected Content
3. Web Fonts (Fall back font getting replaced with the new font)
Steps to prevent CLS:-
1. Always include size attributes on your images and video elements, or otherwise reserve the required space with something like CSS aspect ratio boxes
2. Never insert content above existing content, except in response to a user interaction.
Resource I used to learn about this:-
https://web.dev/cls/
Published
Author
user-image
Iffyuva
In order to take a database dump or restore it on fly.io, use flyctl proxy 5499:5432 -a . Then one can do psql postgres://:@localhost:5499/ to connect to the remote db
Published
Author
user-image
Sujay
Postgres index names are limited to maximum length of 63 characters.
If index name is longer than 63 characters while running rails migration it throws error

Code

Index name 'index_external_reservation_airport_transfers_on_external_reservation_id' on table 'external_reservation_airport_transfers' is too long; the limit is 63 characters


Fix is to explicitly specify the index name

Code

t.references :external_reservation, null: false, foreign_key: true, index: {:name => 'idx_external_reservation_airport_transfers_external_reservation'}

Published
Author
user-image
Syed Sibtain
System Analyst
If we want to query data for specific pages we can use PageQuery, however we cannot directly access the data. We will need to first destructure it first and then it can be passed as props.


Code

const IndexPage = (data) => {

Published
Author
user-image
Ayush Srivastava
System Analyst
Styled components : const Content = styled.div margin: 30px 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-gap: 2rem; ;
lorem ipsum

lorem ipsum will inherit all the styles passed in Content component

cc: @iffyuva
Published
Author
user-image
Iffyuva
is this getting recorded now. Take 5
Published
Author
user-image
Revath
found in very hardway that typeorm has timestamp & timestamptz as types. and this works differently.

Showing 49 to 51 of 82 results

Ready to Build Something Amazing?

Codemancers can bring your vision to life and help you achieve your goals