ReactJS useMemo Hook

Rahul Bansal
Updated on 19-Mar-2021 10:55:25

885 Views

In this article, we are going to see how to optimize a React application by passing a memoized value.This hook is used to optimize the React application by returning a memoized value which helps to prevent doing the complex calculations on every re-rendering. This hook stores the cached value and only updates the function on certain defined conditions.Note: Don’t call side-effects in useMemo hooks; use useEffect hook instead.Syntaxconst memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);Here, the returned value of computeExpensiveValue() function will only be changed on the next re-render if the values of a or b change.Without useMemo HookExampleIn ... Read More

ReactJS useLayoutEffect Hook

Rahul Bansal
Updated on 19-Mar-2021 10:52:31

386 Views

In this article, we are going to see how to set up side-effects or HTTP requests in a functional component.This hook has the similar functioning like that of useEffect hooks but rather than being called out asynchronously, it has a synchronous effect. This hook is used to load the data in the DOM synchronously and also works in the same phase like that of useEffect hook.Note: Use useLayoutEffect hook only if useEffect hooks don't give the expected output.SyntaxuseLayoutEffect()ExampleIn this example, we will build a React application that displays and updates the name synchronously.App.jsximport React, { useLayoutEffect, useState } from 'react'; ... Read More

ReactJS useImperativeHandle Hook

Rahul Bansal
Updated on 19-Mar-2021 10:50:36

941 Views

In this article, we are going to see how to customize the instance value of the ref object.Both useImperativeHandle and useRef hook allows to pass the ref object but the latter one doesn’t allow to customize the instances that are also passed with the ref object. useImperativeHandle hooks is different from the useRef hook in majorly two ways −It allows handling and customizing the returned value explicitly.It allows you to replace the native instances of the ref object with the user-defined ones.SyntaxuseImperativeHandle(ref, createHandle, [deps])ExampleIn this example, we are going to build a custom Button Component that has a user-defined instance attached ... Read More

Array Within a Structure in C Programming

Bhanu Priya
Updated on 19-Mar-2021 10:47:59

5K+ Views

An array of structure in C programming is a collection of different datatype variables, grouped together under a single name.General form of structure declarationThe structural declaration is as follows −struct tagname{    datatype member1;    datatype member2;    datatype member n; };Here, struct is the keyword.tagname specifies the name of structure.member1, member2 specifies the data items that make up structure.ExampleThe following example shows the usage of array within a structure in C programming −struct book{    int pages;    char author [30];    float price; };ExampleFollowing is the C program to demonstrate the use of an array within a structure ... Read More

ReactJS useEffect Hook

Rahul Bansal
Updated on 19-Mar-2021 10:47:57

876 Views

In this article, we are going to see how to set up side-effects or HTTP requests in a functional component.This hook is used to set up subscriptions, handle side-effects or to send analytics data to the server. It is the combination of componentDidMount, componentDidUpdate and componentWillUnmount methods of class-based components. The function passed to this hook will run only after the component is rendered.SyntaxuseEffect(()=>{}, []);()=>{} − Function passed to this hook[ ] − It tells the hook when to re-render the component. For example −[props] − If props values are changed then this hook is called again.[ ] − This ... Read More

ReactJS useDebugValue Hook

Rahul Bansal
Updated on 19-Mar-2021 10:47:33

285 Views

In this article, we are going to see how to debug the custom hooks with the useDebugValue hook in ReactJS.This hook provides custom labels to custom hooks so as to make the process of debugging easier and efficient. It is only called when the React Developer tools are toggled on.SyntaxuseDebugValue(value, ()=>{})ParametersValue − Label for the custom hook.()=>{} − Function to format the label.ExampleIn this example, we will build a React application that displays a custom label for the custom hook of our React application.App.jsxfunction useCustomHook(val) {    const [value, setValue] = useState(null);    useDebugValue(value ? Not Empty : Empty);   ... Read More

ReactJS useContext Hook

Rahul Bansal
Updated on 19-Mar-2021 10:46:59

810 Views

In this article, we are going to see how to access the data without passing it through every parent component in the React Lifecycle.This hook is the better replacement of the Context API of the Class-based component which is used to set the global data and this data can now be accessed in any of the children components without the need to pass it through every parent Component.Syntaxconst authContext = useContext(initialValue);The useContext accepts the value provided by React.createContext and then re-render the component whenever its value changes but you can still optimize its performance by using memoization.ExampleIn this example, we ... Read More

C Program Demonstrating Concepts of Strings Using Pointers

Bhanu Priya
Updated on 19-Mar-2021 10:16:59

2K+ Views

An array of characters is called a string.DeclarationThe syntax for declaring an array is as follows −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.Now, let us understand what are the arrays of pointers in C programming language.Arrays of pointers: (to strings)It is an array whose elements are ptrs to the base add of the string.It is declared and initialized as follows ... Read More

Print Array of Pointers to Strings and Their Address in C

Bhanu Priya
Updated on 19-Mar-2021 10:04:52

8K+ Views

First, let us understand what are the arrays of pointers in C programming language.Arrays of pointers: (to strings)It is an array whose elements are ptrs to the base add of the string.It is declared and initialized as follows −char *a[ ] = {"one", "two", "three"};Here, a[0] is a pointer to the base add of string "one".         a[1] is a pointer to the base add of string "two".         a[2] is a pointer to the base add of string "three".AdvantagesThe advantages of array of pointers are explained below −Unlink the two dimensional array of characters, in ... Read More

What is strstr Function in C Language

Bhanu Priya
Updated on 19-Mar-2021 10:03:30

894 Views

The C library function char *strstr(const char *haystack, const char *needle) function finds the first occurrence of the substring needle in the string haystack. The terminating '\0' characters are not compared.An array of characters is called a string.DeclarationThe syntax for declaring an array is as follows −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.The strstr() FunctionIt is used to search whether ... Read More

Advertisements