Skip to content

Instantly share code, notes, and snippets.

View talhatahir's full-sized avatar

Talha Tahir talhatahir

View GitHub Profile
@talhatahir
talhatahir / react-suspense.js
Created February 28, 2021 16:30
Correct way to use React Suspense
/*
1. The first issue is that Suspense requires a fallback prop which can be a React Component to be shown to the user as a fallback while the original component
in Suspense loads. The code is missing the fallback Prop.
2. The second issue is that this code is rendering components first and then fetching which actually is not how Suspense is used, Suspense is used to fetch data
and render the component all at the same time.
3. For Suspense to work correctly, the fetchUserProfile API call should be similar to React Relay which allows a user to read bits and chunks of data as it
becomes available. At the moment, fetchUserProfile looks more like a simple API returning a prmoise which will not work with Suspense.
*/
@talhatahir
talhatahir / chatgpt-translate.js
Created January 27, 2024 14:58
Auto Translate your App using ChatGPT OpenAI and i18n
require('dotenv').config()
const fs = require('fs')
const OpenAI = require('openai')
//make sure you have the OPENAI_API_KEY in your .env file
const OPENAI_API_KEY = process.env.OPENAI_API_KEY
const openai = new OpenAI({
apiKey: OPENAI_API_KEY,