Skip to content
the poor coder

react avoid spreading non-dom props across component

Poor Man
Published
Reading time
2 min read
JavaScript

        // React lets you assign arbitrary properties to components.
        // These properties can be used to add custom functionality or data to components. 
        // However, React prohibits the transfer of these properties from one component to another.
        // This helps make sure that components are self-contained, and prevents unexpected side effects.
        // The mechanism that prevents non-DOM props from being spread is called “context”.
        // It’s a feature of React that allows you to pass data down the component tree without having to explicitly pass it to each level.
        // When a component receives a prop, it checks to see if it’s a DOM prop or not. 
        // If it isn’t, it stores it in the context object. 
        // This object is then passed down the tree, and any child components can access it. 
        // This allows components to access props without having to pass them explicitly.
    

To prevent non-DOM props from being spread across components, React provides a mechanism called context. Context is a feature of React that allows developers to pass data down a component tree without having to explicitly pass it to each level. When a component receives a prop, it checks to see if it’s a DOM prop or not. If it isn’t, it stores it in the context object. This context object is then passed down the tree and each child component has access to it. This allows components to access props without having to pass them explicitly. It is also important to note that React does not allow arbitrary properties to be passed across components. This is a safeguard to prevent unexpected side effects and to make components self-contained.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC