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
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
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
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
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
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
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 strrev( ) FunctionThis function is used for reversing a string.The reversed string is stored in the same string.SyntaxThe syntax for strrev() function is as follows −strrev (string)ExampleThe following program shows the usage of strrev() function.#include main ( ... Read More
The C library function int strncmp(const char *str1, const char *str2, size_t n) compares at most the first n bytes of str1 and str2.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 strncmp ( ) FunctionThis function is used for comparing first ‘n’ characters of 2 ... Read More
The C library function int strcmp(const char *str1, const char *str2) compares the string pointed to, by str1 to the string pointed to by str2.An array of characters is called a string.DeclarationFollowing is the declaration for an array −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 strcmp() functionThis function compares two strings.It returns the ASCII difference of the first two non ... Read More
The C library function char *strncat(char *dest, const char *src, size_t n) appends the string pointed to by src to the end of the string pointed to by dest up to n characters long.An array of characters is called a string.DeclarationFollowing is the declaration for an array −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 strncat( ) functionThis is used for combining ... Read More