我有一个使用 Gatsby (带有gatsby-plugin-image
)的网站,我正在尝试重构为 Typescript。这是我第一次接触 ts
我有一个布局页面,它使用页面查询来提取 Mdx 数据,但是我缺少一些类型,并且想知道是否有人可以为我指出正确的方向。
我正在努力寻找应该导入和使用的类型:
childImageSharp: {fixed:???}
MdxQuery = {body: ???}`
Run Code Online (Sandbox Code Playgroud)
在处理图像的旧gatsby-image
方法中,它使用 的类型,FixedObject
但这不再有效。
对于这些缺失的类型,有人能为我指出正确的方向吗?
type Frontmatter = {
title: string;
titlestrap: string | null;
category: string;
slug: string;
metaDescription: string | null;
author?: string | null;
featuredImage: {
childImageSharp: {
fixed: any; // what here?
gatsbyImageData: IGatsbyImageData;
};
};
};
type MdxQuery = {
id: string;
body: any; // what here?
frontmatter: Frontmatter;
excerpt: string;
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试按今天、本周、本月和前几个月对一堆日期进行分组。然而,在我达到这一点之前,我什至都在努力按月进行基本分组。
const data = [{
campaign: "Charles",
company_ID: "1",
coreURL: "http://www.test77.com",
createdAt: "2017-11-06T20:45:56.931Z",
owner: "K7xTxu7PRDCuhFZRC",
updatedAt: "2017-09-06T20:45:56.931Z",
_id: "6gsb42PSSJt7PgsDG"
}, {
campaign: "Charles",
company_ID: "1",
coreURL: "http://www.test66,com",
createdAt: "2017-11-06T20:46:27.744Z",
owner: "K7xTxu7PRDCuhFZRC",
updatedAt: "2017-10-06T20:46:27.744Z",
_id: "Md4wCnEsrQrWApnLS"
}, {
campaign: "Gary",
company_ID: "1",
coreURL: "http://www.test55,com",
createdAt: "2017-11-06T20:46:27.744Z",
owner: "K7xTxu7PRDCuhFZRC",
updatedAt: "2017-07-06T20:46:27.744Z",
_id: "5p44uiwRgqp35YXRf"
}
];
const grouper = 'updatedAt';
let groupedData = _
.chain(data)
.groupBy(datum => moment(datum.grouper).format("MM"))
Run Code Online (Sandbox Code Playgroud)
编辑:然而,这似乎只按“11”(今天的月份)分组
任何帮助将非常感激
我在子组件中有一个模态,它处理父组件中的删除功能。孩子保持着模态的状态(打开或关闭),因为这似乎是最合乎逻辑的地方。
家长
removeItem() {
console.log('clicked');
};
...
<DeleteButton deleterecord={()=>this.removeItem(data.row._original._id)}/>
Run Code Online (Sandbox Code Playgroud)
孩子
close() {
this.setState({ showModal: false })
};
open() {
this.setState({ showModal: true })
};
render() {
return(
<div>
<Button
bsStyle="primary"
bsSize="small"
onClick={this.open.bind(this)}
>
Delete
</Button>
<Modal
show={this.state.showModal}
onHide={this.close.bind(this)}
bsSize="small"
>
...
Run Code Online (Sandbox Code Playgroud)
在 removeItem 代码运行后,我应该如何从父级关闭模式。
我想要实现一种“盲目效果”,点击按钮将导致覆盖 div 动画化,因此只有一小部分显示在屏幕顶部,并显示下面的 div。
我正在使用 gatsby,带有 React spring 和样式组件。我已将“百叶窗”设置为组件,如下所示:-
const HeroWrapper = styled(animated.div)`
background-color: blue;
height: 100vh;
width: 100vw;
text-align: center;
position: fixed;
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: column;
z-index: 15;
`
const HeroTitle = styled.h1`
margin: auto;
color: whitesmoke;
`
const Hero = () => {
const [isHeroOpen, setHeroOpen] = useState(true)
const heroAnimation = useSpring({
transform: isHeroOpen ? `translate3d(0,0,0)` : `translate3d(0, -85%, 0)`,
})
return (
<HeroWrapper style={heroAnimation} onClick={() => setHeroOpen(!isHeroOpen)}>
<HeroTitle>I am a Hero Blind</HeroTitle>
<div …
Run Code Online (Sandbox Code Playgroud) 我有一个用作react-table
数据网格的函数。它最初是通过本地状态从父组件中的 Apollo 填充的,网格中的每一行都是数组中的对象。
当网格中的单元格发生变化时,整条线对象都会被写入状态。
我正在尝试使用 useEffect 触发一个突变,将这些状态更改写回数据库,但我正在努力解决两个主要问题:
主要功能(部分)
function Table2({ columns, data }) {
const [lines, setLines] = useState(data);
const [updateLine, {loading, error }] = useMutation(UPDATE_ITEM_MUTATION, {
variables:{ ...lines}
});
useEffect(() => {
updateLine
},[lines]);
const updateMyData = (rowIndex, columnID, value) => {
setLines(getLines =>
getLines.map((row, index) => {
if (index === rowIndex) {
console.log(row)
return {
...lines[rowIndex],
[columnID]: value
};
}
return row;
})
);
};
Run Code Online (Sandbox Code Playgroud)
还有突变……
const UPDATE_ITEM_MUTATION = gql`
mutation UPDATE_LINE_MUTATION( …
Run Code Online (Sandbox Code Playgroud) reactjs ×3
javascript ×2
apollo ×1
gatsby ×1
gatsby-image ×1
lodash ×1
mdxjs ×1
momentjs ×1
react-apollo ×1
react-spring ×1
typescript ×1