我喜欢 graphql。因为它只有一个端点,我只能提取我需要的数据。
所以我使用 apollo-server 作为服务器,使用 apollo-client 作为客户端。
从 apollo-client 3.0 开始,支持状态管理。
apollo-client的reactive变量功能很方便,但我更喜欢redux。
Redux工具包还缩短了需要编写的代码长度。
问题是这样的。
apollo-client 3.0 和 redux 不能一起使用吗?
我不能在 redux 上只使用 graphql 而不使用 apollo-client 吗?那么如何呢?
请检查!
Web 浏览器中的单线程、事件循环和回调的概念与 Node.js 相同?
如果是这样,是不是因为 v8 在工作中使用了这个概念(chrome 和 node.js 都使用 v8)?
v8就是这么设计的吗?
我正在用打字稿做反应项目。
这是我在 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) 我正在使用redux和redux-toolkit进行本地状态管理。我阅读了redux-toolkit文档。我发现我们可以createAsyncThunk()使用redux-toolkit. 该函数自动调度pending、fulfilled、rejected动作。
当我的异步工作失败时,将调度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) 我正在使用打字稿进行类型检查功能。
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) 我想按照我请求的顺序获取帖子。
幸运的是,有一个查询参数 -> 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 方式删除它?
redux ×3
typescript ×3
apollo ×1
graphql ×1
javascript ×1
node.js ×1
reactjs ×1
v8 ×1
wordpress ×1