This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// All your menu options go here. | |
const [menuItems, setMenuItems] = useState([ | |
{ id: '1', name: 'Age', }, | |
{ id: '2', name: 'Price', }, | |
]) | |
// this holds the keys of the menuItems for the view to know which category is currently being rendered. | |
const [selectedItem, setSelectedItem] = useState('1') | |
<View style ={styles.content}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Fragment, useState, useEffect } from 'react' | |
import axios from 'axios' | |
function DemoComponent() { | |
const [data, setData] = useState() | |
const url = 'http://dummy.restapiexample.com/api/v1/employees' // sample api | |
const [isLoading, setIsLoading] = useState(false) | |
const [isError, setIsError] = useState(false) | |
useEffect(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react' | |
import axios from 'axios' | |
export const useFetchEffect = (url) => { | |
const [isLoading, setIsLoading] = useState(false) | |
const [isError, setIsError] = useState(false) | |
const [responseData, setResponseData] = useState(null) | |
useEffect(() => { | |
const fetchData = async () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from 'react' | |
import { useFetchEffect } from '../../hooks/useFetchEffect' | |
const DemoComponent = () => { | |
const url = 'https://jsonplaceholder.typicode.com/posts' // sample api | |
const data = useFetchEffect(url) | |
return <div className="DemoComponent">{data.map(<div>{data.name}</div>)}</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from 'react' | |
import { useFetchEffect } from '../../hooks/useFetchEffect' | |
const DemoComponent = () => { | |
const url = 'https://jsonplaceholder.typicode.com/posts' // sample api | |
const data = useFetchEffect(url) | |
// (optional) you can add your own useEffects e.g. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { useFetchEffect } from '../../hooks/useFetchEffect' | |
const AnotherComponent = () => { | |
const url = 'https://anotherAPIEndpoint.com/route' // sample api | |
const responseData = useFetchEffect(url) | |
const {isLoading, data} = responseData // destructure out the data from the hook | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import {actionCreator} from '../../redux/actionCreators.js' | |
import { useFetchEffect } from '../../hooks/useFetchEffect' | |
const AnotherComponent = () => { | |
const url = 'https://anotherAPIEndpoint.com/route' // sample api | |
const data = useFetchEffect(actionCreator) | |
return <div className="AnotherComponent">{data.map(<div>{data.name}</div>)}</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git status | |
git add . | |
git commit -m "initial commit" | |
git push -u origin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
// this generates a random 20 char string using upto the first 10 chars from the inputString. | |
// this is used to create a workspace id from workspace name so that the workspace namespace can be easily searchable amongst the pinecone vector database namespaces | |
function createRandomWorkspaceIdFromName(inputString) { | |
const alphanumericInput = inputString | |
.replace(/[^a-zA-Z0-9]/g, '') | |
.slice(0, 10); | |
const remainingLength = 20 - alphanumericInput.length; | |
const randomBytes = crypto.randomBytes(remainingLength * 2); | |
const randomAlphanumeric = randomBytes |