小编Bye*_*oon的帖子

如何将 redux 与 graphql 结合使用

我喜欢 graphql。因为它只有一个端点,我只能提取我需要的数据。

所以我使用 apollo-server 作为服务器,使用 apollo-client 作为客户端。

从 apollo-client 3.0 开始,支持状态管理。

apollo-client的reactive变量功能很方便,但我更喜欢redux。

Redux工具包还缩短了需要编写的代码长度。

问题是这样的。

  1. apollo-client 3.0 和 redux 不能一起使用吗?

  2. 我不能在 redux 上只使用 graphql 而不使用 apollo-client 吗?那么如何呢?

请检查!

apollo graphql redux

4
推荐指数
1
解决办法
2992
查看次数

Nodejs 中的单线程和 Web 浏览器中的单线程相同吗?

Web 浏览器中的单线程、事件循环和回调的概念与 Node.js 相同?

如果是这样,是不是因为 v8 在工作中使用了这个概念(chrome 和 node.js 都使用 v8)?

v8就是这么设计的吗?

javascript v8 node.js

3
推荐指数
1
解决办法
274
查看次数

缺少类型“Provider<AnyAction>”

我正在用打字稿做反应项目。

这是我在 index.ts 中的代码

const store = configureStore(initialStateFromDB);
ReactDOM.render(
  <Provider store={store}>
    <App></App>
  </Provider>,
  document.getElementById('app')
);
Run Code Online (Sandbox Code Playgroud)

我犯了很多错误!

第一的。

Type 'Provider<AnyAction>' is missing the following properties from type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)>[]': length, pop, push, concat, and 25 more.ts(2345)
Run Code Online (Sandbox Code Playgroud)

第二

Conversion of type 'Store<{}, AnyAction> & { dispatch: {}; }' to type 'Provider<AnyAction>' may be a mistake because …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs redux

3
推荐指数
1
解决办法
1216
查看次数

Redux-Toolkit createAsyncThunk 与 Typescript

环境

  1. Redux 工具包
  2. 反应
  3. 打字稿
  4. 格帕赫勒

背景

我正在使用reduxredux-toolkit进行本地状态管理。我阅读了redux-toolkit文档。我发现我们可以createAsyncThunk()使用redux-toolkit. 该函数自动调度pendingfulfilledrejected动作。

当我的异步工作失败时,将调度rejected操作action.error作为一种SerializedError类型。我们可以用函数自定义错误的结果rejectWithValue()。像这样。

const fetchAdminPassword = createAsyncThunk('adminPassword/fetch', async (_, { rejectWithValue }) => {
  try {
    const result = await client.query<{adminPassword: string}>({ query: FETCH_ADMIN_PASSWORD });
    const { data: { adminPassword } } = result;
    return adminPassword;
  } catch (err) {
    rejectWithValue("Error!!");
  }
});



builder.addCase(fetchAdminPassword.rejected, (state, action) => {
  state.fetchError …
Run Code Online (Sandbox Code Playgroud)

typescript redux redux-toolkit

2
推荐指数
1
解决办法
5846
查看次数

typescript 多种类型检查功能

背景

我正在使用打字稿进行类型检查功能。

const checkType = <T>(value: unknown, isTypeFn: (value: unknown) => value is T): T => {
  if (!isTypeFn(value)) {
    console.error(`${isTypeFn} ${value} does not have correct type`);
    throw new Error(`${value} does not have correct type`);
  }

  return value;
};

const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean';

const isString = (value: unknown): value is string => typeof value === 'string';

const isNumber = (value: unknown): value is number => typeof value === 'number';

const isNull …
Run Code Online (Sandbox Code Playgroud)

typescript

2
推荐指数
1
解决办法
66
查看次数

Wordpress WP_Query 删除 ORDER BY wp_posts.menu_order

我想按照我请求的顺序获取帖子。

幸运的是,有一个查询参数 -> orderby = 'post_name__in'。

但是,我以其他顺序收到帖子。

我看到了查询的请求。

这里

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 
FROM wp_posts  
WHERE 1=1  
AND wp_posts.post_name 
IN (
  'post title 1',
  'post title 2',
  'post title 3',
  ) 
AND wp_posts.post_type = 'post' 
AND ((wp_posts.post_status = 'publish')) 
ORDER BY wp_posts.menu_order,
FIELD( 
  wp_posts.post_name, 
  'post title 1',
  'post title 2',
  'post title 3',
  ) 
LIMIT 0, 9
Run Code Online (Sandbox Code Playgroud)

我发现这ORDER BY wp_posts.menu_order是一个问题。

如果我删除它然后在 phpmyadmin 上查询,它运行良好。

我按照我想要的顺序收到帖子。

那么,如何ORDER BY wp_posts.menu_order使用 hook & filter 或其他一些 wordpressful 方式删除它?

wordpress

1
推荐指数
1
解决办法
2433
查看次数