我想直接从allMdx查询返回的列表中呈现 MDX 内容。我将“gatsbyjs”与“gatsby-plugin-mdx”一起使用。
我们来查询一下:
export const query = graphql`
query MyQuery {
allMdx {
nodes {
id
body
frontmatter {
title
slug
}
}
}
}
`;
Run Code Online (Sandbox Code Playgroud)
从官方文档中可以看出https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/#updating-page-templates <MDXRenderer>组件已被删除。所以不再可能做这样的事情:
{data.allMdx.nodes.map((n) => (
<MDXRenderer>{n.body}</MDXRenderer>
))}
Run Code Online (Sandbox Code Playgroud)
相反,现在需要这样做:
function MyComponent({ children }) {
return (
<div>
{children}
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
但我想渲染 MDX,allMdx以便我有一个 MDX 帖子列表,例如,你们知道这是否可能以及如何做到吗?
我想知道是否可以根据 url 来模拟具有不同值的 axios 请求。我使用笑话和打字稿。现在我有这个工作示例:
import axios from 'axios';
import { mocked } from 'ts-jest';
jest.mock('axios');
const mAxios = mocked(axios, true);
mAxios.get.mockResolvedValue({
data: [
{
id: 1,
title: 'john doe',
},
{
id: 2,
title: 'keyboard cat',
},
],
});
Run Code Online (Sandbox Code Playgroud)
它可以工作,但正如您所看到的,无论请求发送到哪里,它总是返回相同的值。我想知道如何才能实现我的目标。
目前我正在开发一个使用 websockets 进行通信的节点服务器。我习惯于在我的应用程序中应用 MVC(或 MC)模式。我想以类似的方式构建我的 socket.io,我的问题是如何以最好的方式做到这一点?
现在我有这样的事情:
实用程序/socket.ts:
type IO = null | SocketIO.Server;
let io: IO;
export function init(ioServer: IO) {
io = ioServer;
}
export function getIO(): IO {
return io;
}
Run Code Online (Sandbox Code Playgroud)
应用程序:
import express from 'express';
...
import { init } from './utils/socket';
import startSockets from './controllers';
const app = express();
...
const server = app.listen(process.env.PORT || 5000);
const io = socketio.listen(server);
if (io) {
init(io);
io.on('connect', startSockets);
}
Run Code Online (Sandbox Code Playgroud)
控制器/index.ts:
import { onConnect } from './connect';
import …Run Code Online (Sandbox Code Playgroud)