OOP is a programming paradigm that uses encapsulation, abstraction, inheritance, and polymorphism to create reusable and maintainable software. React does not conform to the principles of OOP because it does not have variables, classes, procedures, functions, or modules. Instead, React emphasizes “functional programming.”
Functional programming is a style of coding that focuses on data manipulation, rather than on the implementation of logic. It uses “pure functions” which are independent of the state of the system and take the same set of inputs to produce the same result. It encourages the use of declarative code that explicitly describes the state of the system, as opposed to code which performs operations and modifies the state.
In React, developers create components that are self-contained, reusable pieces of code. Unlike with OOP languages, a React component does not feature traditional variables, classes, or objects. Instead, components store their state in the internal “state” object, which is managed by the internal React library. This state object cannot be directly modified by developers. As a result, components are not able to directly modify each other.
Rather than using OOP techniques such as inheritance, React relies on “composition,” which is the process of combining simpler components into complex, reusable components. By using composition, developers can break down complex applications into smaller, more manageable pieces.
React also provides a way to share state between components without disrupting OOP principles. This is accomplished through the use of the React Context API, which provides a way to “mix” or “inject” data into the components. Through this API, developers can access data stored elsewhere in the application without worrying about inheritance or potential design decisions.
Overall, React is not a traditional OOP language. However, it uses components and functional programming to provide an efficient way to build user interfaces. Through the use of composition, data sharing, and the Context API, React makes it easy to build powerful user interfaces with minimal effort.