小编Bla*_*ath的帖子

动作中返回和调度的区别:Redux

我注意到在终极版使用,有时行动returndispatch。我还注意到dispatch当该操作函数中有一些异步操作时使用它,例如从/向数据库读取/发布,但我不明白为什么。谁能解释一下关键的区别。dispatch例如,为什么我们不一直使用,例如 React 中的上下文 API?

编辑:我将添加一个示例,该示例不涉及后端,因此没有async await循环:

 //with return
    export const addLog = (log) => {
       return{
         type: ADD_LOG,
         payload: log
       }
    }
    //with dispatch
    export const addLog = (log) => disptach => {
       dispatch{
         type: ADD_LOG,
         payload: log
       }
    }
Run Code Online (Sandbox Code Playgroud)

两者有什么区别?

reactjs redux

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

svelte 中的 useRef 相当于什么?

我在 svelte 中有一个组件,我需要在其中定义一个名为 的值oldVal,该值不绑定到任何html元素,并将其初始化为值 X。下次组件渲染时,我想将其值更新为 X1,并且该值应该持续到下一次渲染,依此类推。在反应中我们使用useRef这个,但是如何在不编写存储的情况下以svelte实现这个?

编辑:添加一些代码

所以,基本上,我在组件内进行转换,其中我有一个自定义的 css 转换函数

<script>
export let tick;
export let tranX;
import {select} from 'd3-selection';
import {interpolate} from 'd3-interpolate';

// This value is initially 0 but then updated on each render
let oldVal =0;

//Custom CSS transition function
function animateX(node, {duration}){
const xTranslate = +select(node)
      .attr('transform')
      .split('(')[1]
      .split(',')[0];//Here I extract the translate value in the x direction
    const interVal =
      oldVal > xTranslate 
        ? interpolate(xTranslate , oldVal)
        : …
Run Code Online (Sandbox Code Playgroud)

d3.js svelte

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

标签 统计

d3.js ×1

reactjs ×1

redux ×1

svelte ×1