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 { useState } from "react"; | |
| import { useQuery } from "react-query"; | |
| const fetchMovieList = (searchText) => { | |
| return fetch(`https://www.omdbapi.com/?s=${searchText}&apikey=${API_KEY}`) | |
| .then(response => response.json()); | |
| } | |
| function App() { | |
| const [searchText, setSearchText] = useState(""); |
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 { useQuery } from "react-query"; | |
| function App() { | |
| const { isLoading, isError, data, error } = useQuery('movies', fetchMovieList) | |
| } |
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 { useQuery } from "react-query"; | |
| function App() { | |
| const { isLoading, isError, data, error } = useQuery('movies', fetchMovieList) | |
| if (isLoading) { | |
| return <span>Loading...</span> | |
| } | |
| if (isError) { |
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 { ReactQueryDevtools } from 'react-query/devtools' | |
| function App() { | |
| return ( | |
| <QueryClientProvider client={queryClient}> | |
| {/* The rest of your application */} | |
| <ReactQueryDevtools initialIsOpen={false} /> | |
| </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 React from "react"; | |
| import withResponsive from "../../hoc/responsive"; | |
| const Home = (props) => { | |
| const Yes = () => <span style={{ color: "#5cb85c" }}>YES</span>; | |
| const No = () => <span style={{ color: "#d9534f" }}>NO</span>; | |
| return ( | |
| <> | |
| <div> |
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
| /** | |
| * This is an HOC. Use this 'withResponsive' hoc component for responsive UI. | |
| */ | |
| import React from "react"; | |
| import { useMediaQuery } from "react-responsive"; | |
| const withResponsive = (Component) => { | |
| return function (props) { |
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 { useMediaQuery } from 'react-responsive' | |
| const Example = () => { | |
| const isDesktopOrLaptop = useMediaQuery({ | |
| query: '(min-device-width: 1224px)' | |
| }) | |
| const isBigScreen = useMediaQuery({ query: '(min-device-width: 1824px)' }) | |
| const isTabletOrMobile = useMediaQuery({ query: '(max-width: 1224px)' }) | |
| const isTabletOrMobileDevice = useMediaQuery({ |
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, { useContext } from "react" | |
| import AppContext from "../../Store" | |
| export default () => { | |
| const cartContext = useContext(AppContext); | |
| const handleCartUpdate = (id) => { | |
| const productsState = cartContext.data.products.map(product => ({ ...product, addedToCart: (product.id === id ? !product.addedToCart : product.addedToCart) })); | |
| cartContext.updateData({ products: productsState }); | |
| } |
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, { useState } from 'react' | |
| import { ContextProvider } from "./Store" | |
| import { products } from "./constants/data" | |
| import AppRouter from './components/AppRouter'; | |
| function App() { | |
| const [contextData, setContextData] = useState({ | |
| data: { | |
| products: products.map(product => ({ ...product, addedToCart: false })) |
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"; | |
| const AppContext = React.createContext({}); | |
| export const ContextProvider = AppContext.Provider | |
| export const ContextConsumer = AppContext.Consumer | |
| export default AppContext |
NewerOlder