This file contains hidden or 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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
contract Factory { | |
// Returns the address of the newly deployed contract | |
function deploy( | |
uint _salt | |
) public payable returns (address) { | |
// This syntax is a newer way to invoke create2 without assembly, you just need to pass salt | |
// https://docs.soliditylang.org/en/latest/control-structures.html#salted-contract-creations-create2 |
This file contains hidden or 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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.13; | |
contract SimpleWallet { | |
address public owner; | |
// Only owners can call transactions marked with this modifier | |
modifier onlyOwner() { | |
require(owner == msg.sender, "Caller is not the owner"); | |
_; | |
} |
This file contains hidden or 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 { useGithubUser } from '@/api/github.api'; | |
const ReactQueryExample = () => { | |
const { isLoading, error, data } = useGithubUser(); | |
if (isLoading) return 'Loading...'; | |
if (error) console.log('An error occurred while fetching the user data ', error); | |
return ( |
This file contains hidden or 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
// api/github.api.ts | |
import { useQuery } from '@tanstack/react-query'; | |
export type TGithubUser = { | |
name: string; | |
bio: string; | |
}; | |
export const fetchGithubUser = async () => { | |
const res = await fetch('https://api.github.com/users/kiranm27'); |
This file contains hidden or 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
// _app.tsx or index.tsx | |
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | |
const queryClient = new QueryClient(); | |
function MyApp({ Component, pageProps }: AppProps) { | |
return ( | |
<QueryClientProvider client={queryClient}> | |
<Component {...pageProps} /> | |
</QueryClientProvider> |
This file contains hidden or 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 { setUserUid } from '@/redux/slices/userSlice'; | |
import { useEffect } from 'react'; | |
import { useDispatch } from 'react-redux'; | |
const ReduxSetExample = () => { | |
// create an instance of the dispatch function | |
const dispatch = useDispatch(); | |
useEffect(() => { | |
// dispatch the action as such |
This file contains hidden or 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 { RootState } from '@/redux/store'; | |
import { useEffect } from 'react'; | |
import { useSelector } from 'react-redux'; | |
const ReduxFetchExample = () => { | |
// access the redux state as such | |
const { uid } = useSelector((state: RootState) => state.user); | |
useEffect(() => { | |
if (!uid) return; |
This file contains hidden or 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 { store } from '@/redux/store'; | |
import '@/styles/globals.css'; | |
import { AppPropsWithLayout } from '@/types/page'; | |
import { ThemeProvider } from 'next-themes'; | |
import { Provider as ReduxProvider } from 'react-redux'; | |
export default function App({ Component, pageProps }: AppPropsWithLayout) { | |
const getLayout = Component.getLayout ?? ((page) => page); | |
return ( |
This file contains hidden or 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
// redux/slices/userSlice.ts | |
import { PayloadAction, createSlice } from '@reduxjs/toolkit'; | |
import { IUser } from '../redux.types'; | |
const initialState: IUser = { | |
uid: '', | |
email: '', | |
}; | |
export const userSlice = createSlice({ |
This file contains hidden or 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
// redux/redux.types.ts | |
export interface IUser { | |
uid: string; | |
email: string; | |
} |
NewerOlder