小编eri*_*s93的帖子

具有动态图像源的可重复使用的盖茨比图像组件

我正在考虑将Gatsby-Image用于我的下一个项目,并且已经对其进行了一些尝试。

我可以在测试项目中使用它,但是后来我想到了一个用例,我想像常规<img src”image.png”>标记一样使用Gatsby中的。因此,我的问题是如何使Gatsby组件可重用?

import React from "react"
import { StaticQuery, graphql } from "gatsby"
import Img from "gatsby-image"
function renderImage({ file }) {
  console.log({ file })
  return <Img fluid={file.childImageSharp.fluid} />
}

// Stateless Image component which i guess will recieve src value as a prop?
// Returns a StaticQuery component with query prop and render prop. Query prop has the graphql query to recieve the images and render prop returns a renderImage function which in return, returns a …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs graphql gatsby

8
推荐指数
2
解决办法
2112
查看次数

打字稿:对象可能是“空”

我正在尝试将 React 项目转换为 TypeScript。下面的代码是一个输入字段,用于计算正在输入的字符数。

在 renderCharactersLeft 函数中,我收到以下错误:

在此处输入图片说明

由于默认状态 'charsLeft' 设置为 null,这并不让我感到惊讶,但我想知道您将如何在 TypeScript 中绕过或解决此消息?

import React from "react";

interface CharCountInputProps {
  value: string;
  type: string;
  name: string;
  maxChars: number;
  onChange: any;
}

interface CharCountInputState {}

class CharCountInput extends React.Component<
  CharCountInputProps,
  CharCountInputState
> {
  state = {
    charsLeft: null
  };

  componentDidMount() {
    this.handleCharCount(this.props.value);
  }

  handleCharCount = (value: string) => {
    console.log(value);
    const { maxChars } = this.props;
    const charCount = value.length;
    const charsLeft = maxChars - charCount;
    this.setState({ charsLeft });
  };

  changeHandler …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs

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

GIT 无法从远程存储库读取

我已经克隆了一个私有仓库,将它分叉并在一个功能分支中进行了一些更改。当我尝试将这些更改推送到 repo 时,我收到以下消息:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)

我试图从我的 Windows 计算机控制面板>凭据中删除 git 凭据,但它仍然显示相同的错误。

有没有可能我必须从我的终端登录和退出到 git?如果是这样,我该怎么做?

我也试过用 git push --set-upstream origin 推送,但它只是向我展示了同样的错误。

你们有没有人见过这个?

预先感谢,埃里克

git github

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

标签 统计

javascript ×2

reactjs ×2

gatsby ×1

git ×1

github ×1

graphql ×1

typescript ×1