Skip to content

Instantly share code, notes, and snippets.

@Moizsohail
Last active March 3, 2022 18:41
Show Gist options
  • Save Moizsohail/9014730f5f11c33e381a820e2d6ed3b5 to your computer and use it in GitHub Desktop.
Save Moizsohail/9014730f5f11c33e381a820e2d6ed3b5 to your computer and use it in GitHub Desktop.
Chrome Extension In React With NPM Modules: Part 3
import React, { useState } from "react";
import { Button, Container, FormControl, Navbar } from "react-bootstrap";
import { sendMessage } from "../messaging";
import { MessageTypes } from "../types";
const Home = () => {
//---- new ----
const [text, setText] = useState("");
const handleChange = (e: any) => {
setText(e.target.value);
};
const mooHandler = () => {
sendMessage(MessageTypes.execute, { text: text });
};
//---- end-new ----
return (
<>
<Navbar bg="primary" className="px-3" expand="lg" variant="dark">
<Navbar.Brand>Our Mooo Extension</Navbar.Brand>
</Navbar>
<Container className="w-100 h-100 p-3">
<FormControl
value={text} // new
placeholder="What to Moo?"
onChange={handleChange} //new
></FormControl>
<div className="d-flex mt-3 justify-content-end">
<Button onClick={mooHandler}>Let's Mooo</Button> //updated
</div>
</Container>
</>
);
};
export default Home;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment