小编cba*_*ier的帖子

React useState hooks 错误:“xxx”类型的参数不可分配给“SetStateAction<xx>”类型的参数

我使用 react hooks 来更新,但是在 setState 时会注意到错误。

'{ alertRules: any; 类型的参数 }' 不能分配给'SetStateAction' 类型的参数。对象字面量只能指定已知属性,并且类型“SetStateAction”中不存在“alertRules”.ts(2345)

这是我的代码。

import React, { useState, useEffect } from 'react';
import { FieldArray } from 'redux-form';
import { CoordinateSelect } from '~/fields';
import lodash from 'lodash';
import { connect } from 'react-redux';
import { filterDispatchers } from '~/actions';
import t from '~/locale';

interface Props {
  getAlertRules(o: object): Promise<any>;
}
type Alert = {
  ...
}

const connector = connect(
  null,
  filterDispatchers('getAlertRules'),
);

const AlertRuleForm = (props: Props) => …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs tsx react-hooks

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

日期序列化后 Laravel 7 中的时区错误

我正在开发一个新的 Laravel 7.1 应用程序(不是升级)但似乎使用日期序列化会丢失时区。

配置/app.php

'timezone' => 'Europe/Zurich',
Run Code Online (Sandbox Code Playgroud)

修补匠的例子

>>> \Carbon\Carbon::parse('2020-06-22')->timezone
=> Carbon\CarbonTimeZone {#3251
     timezone: Europe/Zurich (+01:00),
   }
Run Code Online (Sandbox Code Playgroud)

Laravel 7 使用 toJson()

>>> \Carbon\Carbon::parse('2020-06-22')->toJson()
=> "2020-06-21T22:00:00.000000Z"
Run Code Online (Sandbox Code Playgroud)

所以,当我解析日期时,我没有得到正确的日期。

>>> new \Carbon\Carbon('2020-06-21T22:00:00.000000Z')
=> Carbon\Carbon @1592776800 {#3266
     date: 2020-06-21 22:00:00.0 +00:00,
     timezone: "Z",
   }

>>> (new \Carbon\Carbon('2020-06-21T22:00:00.000000Z'))->format('Y-m-d')
=> "2020-06-21"

Run Code Online (Sandbox Code Playgroud)

目前我正在这样做

$date = Carbon::parse('2020-06-21T22:00:00.000000Z')
    ->setTimezone(config('app.timezone'));
Run Code Online (Sandbox Code Playgroud)

作为替代方案,我可以更改模型中的默认日期格式,如文档中所述

/**
 * Prepare a date for array / JSON serialization.
 *
 * @param  \DateTimeInterface  $date
 * @return string
 */
protected function serializeDate(DateTimeInterface $date)
{
    return $date->toIso8601String(); …
Run Code Online (Sandbox Code Playgroud)

php php-carbon laravel-7

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

PHP 更新到 PHP 8.1 RC5 后无法运行

将 PHP 7.4 更新到 PHP 8.1 RC5 后,PHP 在我的机器上停止工作并产生以下错误:

PHP 警告:PHP 启动:^(text/|application/xhtml+xml) (offset=0):第 0 行“未知”中无法识别的编译时选项位

即使我询问 php 版本,它也会产生错误:

PHP Warning:  PHP Startup: ^(text/|application/xhtml\+xml) (offset=0): unrecognised compile-time option bit(s) in Unknown on line 0
PHP 8.1.0RC5 (cli) (built: Nov  4 2021 14:57:53) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.0RC5, Copyright (c), by Zend Technologies
Run Code Online (Sandbox Code Playgroud)

操作系统:Ubuntu 20.04

使用此存储库更新:

sudo add-apt-repository ppa:ondrej/php
Run Code Online (Sandbox Code Playgroud)

你知道问题出在哪里吗?

php php-8.1

9
推荐指数
2
解决办法
4120
查看次数

在 Laravel 中使用 foreach 上传文件

已经在这个问题上工作了 2 天,但仍然无法弄清楚。我正在尝试将多个文件上传到我的 Laravel 项目中的存储中。我知道我的代码适用于 foreach,因为我用 dd 对此进行了测试。

我的控制器:

$files = $request->file('current_plan_year_claims_data_file_1');
$folder = public_path(). "\storage\\$id";

if (!File::exists($folder)) {
    File::makeDirectory($folder, 0775, true, true);
}

if (!empty($files)) {
    foreach($files as $file) {
        Storage::disk(['driver' => 'local', 'root' => $folder])->put($file->getClientOriginalName(), file_get_contents($file));
    }
}
Run Code Online (Sandbox Code Playgroud)

laravel

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

API cURL调用出错:{"errors":{"price_rule":"必需参数丢失或无效"}}

我在基于所选产品的价格规则的cURL调用中收到错误.以下是我的错误:

{
   "errors":{
      "price_rule":"Required parameter missing or invalid"
   }
}
Run Code Online (Sandbox Code Playgroud)

以下是我在cURL电话中发送的身体参数:

{
   "price_rule":{
      "title":"sss",
      "target_type":"line_item",
      "target_selection":"entitled",
      "allocation_method":"across",
      "value_type":"fixed_amount",
      "value":"-434",
      "customer_selection":"all",
      "prerequisite_quantity_range":{
         "greater_than_or_equal_to":"2"
      },
      "entitled_product_ids":{
         "0":"2397130326093",
         "1":"2397129965645",
         "2":"2397131898957",
         "3":"2397132324941"
      },
      "starts_at":"2019-02-22T08:08:53.000Z"
   }
}
Run Code Online (Sandbox Code Playgroud)

以下是我的cURL电话:

$ch = curl_init();    
// curl_setopt($ch, CURLOPT_POST, count($newrule));
curl_setopt($ch, CURLOPT_URL, $access_token_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($pro_ids11));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Shopify-Access-Token: '.$shops_token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_error($ch)) {
    $error_msg = curl_error($ch);
}
curl_close($ch);
if (isset($error_msg)) {
    echo $error_msg;
}
Run Code Online (Sandbox Code Playgroud)

请注意我在PHP工作.提前致谢!

php laravel shopify-app

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