Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 5211

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 27, 20242024-11-27T07:09:08+00:00 2024-11-27T07:09:08+00:00

Browser extensions – spicing it up with React

  • 61k

Now that we have our Browser extension up and running with Tailwind CSS and Parcel let's look at how we can make it more interactive.

You can choose any framework you are familiar with. I decided to go with React for this one.

The idea is to add React to have an interactive new tab browser extension.

Browser extensions - spicing it up with React

Note: if you want to follow along, use the following GitHub branch.

Installing the dependencies

First, we must let our project know we plan to use React, so let's install the needed dependencies.

npm i react react-dom 
Enter fullscreen mode Exit fullscreen mode

Then you can go ahead and create an src folder. It will become the central place of our React application.

Setting up React

Now that we have everything installed, those two are the only ones we need 🤯.

We can go ahead and render the React app.
Open up your new-tab.html page. Until now, this was our application's source, but let's remove the HTML and place this inside.

<body>   <div id="app"></div>   <script type="module" src="index.js"></script> </body> 
Enter fullscreen mode Exit fullscreen mode

This will become our injection point as to where we can inject React.

We also added a script that will handle the React injection.

Go ahead and create this index.js file.

import ReactDOM from 'react-dom'; import { App } from './src/App';  const app = document.getElementById('app'); ReactDOM.render(<App />, app); 
Enter fullscreen mode Exit fullscreen mode

Now we can move on to creating this App component.
Add the App.js file in your src directory and place the following contents inside.

export function App() {   return (     <div className='flex flex-col items-center justify-center w-screen h-screen bg-indigo-400 text-6xl font-bold text-white'>       <p>Welcome 👋</p>     </div>   ); } 
Enter fullscreen mode Exit fullscreen mode

This will render what we already had in the first place.
Let's make it more interactive by creating a Counter.js component.

import { useState } from 'react';  export default function Counter() {   const [counter, setCounter] = useState(0);   const increase = () => setCounter((count) => count + 1);   const decrease = () => setCounter((count) => count - 1);   return (     <div>       <button onClick={decrease}>-</button>       <span className='px-4'>{counter}</span>       <button onClick={increase}>+</button>     </div>   ); } 
Enter fullscreen mode Exit fullscreen mode

Now go back to the App.js component and import the Counter.

import Counter from './Counter';  export function App() {   return (     <div className='flex flex-col items-center justify-center w-screen h-screen bg-indigo-400 text-6xl font-bold text-white'>       <p>Welcome 👋</p>       <br />       <Counter />     </div>   ); } 
Enter fullscreen mode Exit fullscreen mode

Now, if you run your watch or build command, you should be able to use your new React-powered browser extension.

npm run build 
Enter fullscreen mode Exit fullscreen mode

Note: ensure to use the dist folder when loading the extension

React powered browser extension

You can find this article's code on GitHub.

Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter

beginnershtmlreactwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.