Skip to content

Instantly share code, notes, and snippets.

View cdsandoval's full-sized avatar
🧑‍💻
Becoming a Full Stack Web Developer

Carlos Sandoval Montoya cdsandoval

🧑‍💻
Becoming a Full Stack Web Developer
View GitHub Profile
@cdsandoval
cdsandoval / useMemo.jsx
Last active February 8, 2024 11:24
useMemo
function Component(){
const [searchTerm, setSearchTerm] = React.useState("")
const filterWithGoodName = React.useMemo(() => {
return searchTerm.filter(.....)
}, [searchTerm])
return (
<input onSearch={setSearchTerm}/>
}
@cdsandoval
cdsandoval / helper.js
Last active June 9, 2023 17:55
Refactor ransack fiilter with search term
function buildSearchGroups(term, searchFields) {
const searchGroups = [];
if (term) {
const searchTermList = term.trim().split(' ');
searchTermList.forEach(searchTerm => {
const searchGroup = { m: 'or' };
searchFields.forEach(field => {
HOC is a function with a component that return a new component.
//geolocation.js
function withGeolocation(Component) {
function Geolocation() {
const [latitude, setLatitude] = React.useState(0);
const [longitude, setLongitude] = React.useState(0);
React.useEffect(() => {
@cdsandoval
cdsandoval / async fetch
Created June 23, 2019 06:21
How would you async fetch data for a React component
Using hooks with useEffect like this :
useState(async ()=>{
const response = await fetch(url);
const json = await response.json();
setData(json);
}
- with Classes using compenentDidMount or willMount :
@cdsandoval
cdsandoval / async fetch
Created June 23, 2019 06:21
How would you async fetch data for a React component
Using hooks with useEffect like this :
useState(async ()=>{
const response = await fetch(url);
const json = await response.json();
setData(json);
}
- with Classes using compenentDidMount or willMount :
@cdsandoval
cdsandoval / index.html
Created January 22, 2019 05:04
Calculadora de Tips
<!DOCTYPE html>
<html>
<head>
<title>Propinas</title>
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="css/styles.css" />
</head>
<body>
<div id="container">