top of page
take-care-of-your-camera.avif

Programming Styles

Declarative Programming

- React.js follows declarative programming approaches.

​

- Core to React ‘s design.

​

- Developers describe what they want the UI to look like, not how to achieve it (React.JS, Imperative or Declarative Programming? | by Muhsin Sutanto | Medium, n.d.).

Object-Oriented Programming (OOP)

- React used to rely more on class components, which follow OOP principles, but functional components with hooks are now preferred.

​

- React allows developers to create components using function-based syntax or class-based syntax. Class components were commonly used in React, though functional components are now the preferred way (Why and How to Use Object-Oriented Programming (OOP) Concepts in React | by Oshadhadushan | Nov, 2024 | Medium, n.d.).

Functional Programming

- React encourages using functional components and concepts like pure functions and immutability.

​

Pure functions: Function that return the same result given the same inputs and have no side effects.​

​

Immutability: Data cannot be changed once created. Instead, new data structures are returned with necessary changes.

​

- The use of functional components, hooks, and immutable state management aligns well with functional programming concepts.

​

- Benefits:

Functional programming encourages the use of small, reusable functions, which can be easily composed to build more complex functionality.

Pure functions are easier to test because they don’t have any side effects, making it simpler to verify their behavior.

​

Immutable data structures can lead to performance improvements, as React can more efficiently determine when a component needs to re-render (Functional Programming In React | Saeloun Blog, n.d.).

- Chang Hui Ming
bottom of page