我有以下用户片段:
{
/*
// Place your snippets for JavaScript React here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Print to console": {
"prefix": …Run Code Online (Sandbox Code Playgroud) 我正在使用 RTK 查询来获取一些数据。我需要访问应用程序中各个组件的加载状态,但我不确定如何执行此操作。
我觉得这可能只是我误解了如何在更大的应用程序中正确使用 RTK 查询。大多数示例都是单个组件,我不太明白如何从各个组件访问单个查询的各种状态。
例如,我需要在应用程序的主要部分显示一个加载程序,其中数据是从查询生成的。然后,我需要在侧边栏的一小部分中显示一个完全不同的加载器,其中包含一些通过相同的 API 查询生成的内容详细信息。
这如何与 RTK 查询配合使用?
是否存在使用共享此查询状态/状态的多个组件的示例?
我是否完全错过了对如何在应用程序中使用状态的基本理解?(我感觉这就是这里的哈哈)
我有一个脚本,我想将其分成多个模块。例如,将我所有的鼠标事件放在另一个模块中(mouseup、mousedown 等)。
我使用一堆全局变量来跟踪屏幕上的所有对象。鼠标模块将需要访问这些变量并更改它们。我意识到我可以显示其他模块所需的每个变量,但他们无法更改它们。
使用 Javascript 如何最好地实现这一点?我目前使用揭示模块模式,并且我读到我必须使用 getter 和 setter(例如我从学校回忆的 C++ 中使用的),但是我有很多全局变量需要跟踪。我需要很多这样的方法。这是我应该这样做的方式吗?
或者...这是一个案例,向我展示了一个问题描述了糟糕的设计。
我正在使用 Fabric.js 进行绘图和所有这些工作。
绘制脚本.js
var DrawScript = function(){
var DRAW = 0,
SELECT = 1,
SCROLL = 2;
var MOUSEBUTTONS = {
'S': 83,
'C': 67,
'D': 68,
'DELETE': 46,
'BACKSPACE': 8
};
var canvas;
var _started = false;
var _x, _y;
var square;
var edgedetection = 10; // pixels to snap
var lines = {};
var lines_group;
var rectangles_group;
var rectangle_txt = {};
var _text_offset_x = 20; …Run Code Online (Sandbox Code Playgroud) 我正在尝试将组件连接到redux存储,但是我正在接收:
Warning: Failed prop type: The prop 'store.subscribe' is marked as required in连接(StoreLocation), but its value is 'undefined'.
我一直在使用redux与这个项目一段时间没有问题,但这个组件由于某种原因出错了,我对此为何无能为力:(
商店会在其中填充一系列商店(实体店,地址,电话号码等,用于运送选择)DeliverySection.js.
然后每个StoreLocation.js组件将允许用户查看它的信息,选择它等.它现在是骨头,因为我甚至在这个基本点看到错误.如果我export default connect()(StoreLocation)用export default StoreLocation它切换语句没有问题.
有任何想法吗?
DeliverySection.js
import React, { Component } from 'react'
import { connect } from 'react-redux'
// Components
import Loader from '../../utils/Loader'
import StoreLocation from './StoreLocation'
// Stote
import { getAllStores } from '../../../store/actions/storeLocation'
import { REACT_APP_SITE_KEY } from '../../../shared/vars'
// CSS
import '../../../css/delivery.css'
class DeliverySection …Run Code Online (Sandbox Code Playgroud)