Skip to main content

Featured post

How to Insert line break in Text component in React Native

Hi, I was developing an application in react native.I have to handle lots of text data in this small react native application.I have used  Text component in react native many times. While working on this application,i had a requirement to display some text content with line breaks.I will explain it clearly with an example.I want to display a text as shown below  Welcome Please subscribe my channel I wrote react native code as shown below <View> <Text> Welcome Please subscribe my channel </Text> <View> When i run these lines of code,It will display text as shown below Welcome Please subscribe my channel   - instead of displaying in two lines with line break,it displays in a single line.So i have to find a solution to insert line break in Text component in React Native.After lots of research,i found a clean solution as shown below <View> <Text> Welcome{"\n"} Please subscribe my channel </Text> <View> Here ...

Can we Programmatically navigate React Router using useNavigate hook?

Dear friends,





When we write react code,we may face a requirement to navigate React Router programmatically.Many of us have faced it in their coding journey.So I am going to explain how can we  programmatically navigate  React Router using useNavigate hook.


In order to implement it,we use useNavigate hook.So we will import useNavigate hook from react-router-dom.Please remember that  useNavigate hook introduced in React Router version 6.So it will not applicable if you are using React Router version below 6.


I will share a sample code to understand How to programmatically navigate  React Router 


import * as React from 'react';

import { useNavigate } from 'react-router-dom';


const ContactUsButton = () => {

  const navigate = useNavigate();

  const handleClick = () => navigate('/contact');


  return (

    <button type="button" onClick={handleClick}>

      Contact Us

    </button>

  );

}


I will list main steps to programmatically navigate  React Router using useNavigate hook


1.import { useNavigate } from 'react-router-dom'


2. const navigate = useNavigate();


3. const handleClick = () => navigate('/contact');


I hope,this small article will help you to use features of useNavigate hook.


Thanks