Skip to content

Instantly share code, notes, and snippets.

View Kellswork's full-sized avatar

Kelechi Ogbonna Kellswork

View GitHub Profile
export default function UserList({contacts}) {
return (
<div>
{props.contactList.map((contact) => (
<div className="card" key={contact.phonenumber}>
<p className="card-name">{contact.name}</p>
<p>{contact.email}</p>
<p>{contact.phonenumber}</p>
</div>
))}
@Kellswork
Kellswork / App.js
Created September 29, 2021 22:27
Updated App.js file, imported ContactsList
import { useState } from "react";
import ContactForm from "./components/ContactForm.jsx";
import ContactList from "./components/ContactList.jsx";
import "./App.css";
function App() {
// here we create an array state to store the contact form data
const [contacts, updateContacts] = useState([]);
const addContact = (contact) => {
import { useState } from "react";
export default function UserForm({addContact}) {
const handleSubmit = (event) => {
event.preventDefault();
addContact(contactInfo);
setContactInfo({ name: "", email: "", phonenumber: "" });
@Kellswork
Kellswork / App.js
Created September 29, 2021 22:19
Display Form Data in Another Component
import { useState } from "react";
import ContactForm from "./components/ContactForm.jsx";
import "./App.css";
function App() {
// here we create an array state to store the contact form data
const [contacts, updateContacts] = useState([]);
const addContact = (contactInfo) => {
updateContacts([...contacts, contactInfo]);
@Kellswork
Kellswork / ContactForm.jsx
Created September 29, 2021 22:07
Converting JSX Form to a Controlled Form with React Hooks
import { useState } from "react";
export default function UserForm() {
const [contactInfo, setContactInfo] = useState({
name: "",
email: "",
phonenumber: "",
});
import ContactForm from "./components/ContactForm.jsx";
import "./App.css";
function App() {
return (
<div className="App">
<UserForm />
</div>
);
}
@Kellswork
Kellswork / build-simple-react-form.jsx
Created September 29, 2021 21:56
Build a simple react form with multiple input fields
export default function UserForm() {
return (
<div>
<form>
<div>
<h3>Contact Form</h3>
</div>
<div>
<input
@Kellswork
Kellswork / Brute Force approach.js
Last active May 21, 2021 22:00
Leetcode 121: Best Time to Buy and Sell Stock JavaScript solution
/* Solution using Brute Force approach */
function maxProfit(prices) {
// set maxProfit to zero, this helps for edge case that says return zero when no profit is made
let maxProfit = 0
// we start the buying price at index 0 to get the prices[0]
for(let buyPrice = 0; buyPrice < prices.length; buy++) {
// start sell price with buyPrice + 1 to make sure we aren't going back on the days