[React GraphQL] Pass Parameters to urql's useQuery React Hook
React to 39 hook parameters pass GraphQL
2023-09-14 08:59:15 时间
Showing how to use 'uqrl' library to do GraphQL in React.
import React, {useState} from 'react' import {useQuery} from 'urql' const courseQuery = ` query courses($page: Int) { courses(page: $page) { title } } ` function App() { const [page, setPage] = useState(1) const [result] = useQuery({ query: courseQuery, variables: { page, }, }) if (result.error) { return 'There was an error :(' } return ( <div> <h1>egghead courses</h1> <button onClick={() => setPage(page + 1)}>Next Page</button> {result && result.data && ( <ul style={{listStyle: 'none'}}> {result.data.courses.map(({title}) => ( <li key={title} style={{ display: 'flex', alignItems: 'center', fontSize: 16, fontFamily: 'sans-serif', marginBottom: 10, }} > {title} </li> ))} </ul> )} </div> ) } export default App
相关文章
- React组件继承,泛型写法
- [React Recoil] Use selectors to calculate derived data based on state stored within a Recoil atom
- [React Recoil] Use a Recoil atom to share state between two React components
- [React Testing] Test react-router-dom Router Provider with createMemoryHistory
- [React Router] Create a ProtectedRoute Component in React Router (setState callback to force update)
- [React Intl] Use a react-intl Higher Order Component to format messages
- [React Router v4] Render Multiple Components for the Same Route
- 【REACT NATIVE 系列教程之一】触摸事件的两种形式与四种TOUCHABLE组件详解
- [React] Performance issue - 01 useState with slow function call
- [React] Refactor componentWillReceiveProps() to getDerivedStateFromProps() in React 16.3
- [React] Integration test a React component that consumes a Render Prop
- [React] Configure a React & Redux Application For Production Deployment and Deploy to Now
- [React Intl] Format a Date Relative to the Current Date Using react-intl FormattedRelative
- [React] Create an Auto Resizing Virtualized List with react-virtualized
- [React Fundamentals] Introduction to Properties
- [React] Using the classnames library for conditional CSS
- [Redux] Adding React Router to the Project
- [React] React Fundamentals: Using Refs to Access Components
- atitit.React 优缺点 相比angular react是最靠谱的web ui组件化方案了
- 主流前端框架对比:Vue.js , React, Angular.js