作者:匿名用户
链接:https://www.zhihu.com/question/325397290/answer/708418099
来源:知乎

事实性错误:

那 vue 呢?它连 HOC 都没有,render props 更不现实(jsx自带)

  1. HOC
const DefaultButton = {
props: {
text: String
},
template: `<button>{{text}}</button>`
} function wrap(comp) {
return {
components: {
comp
},
template: `<comp text=""/>`
}
} new Vue({
components: {
TextButton: wrap(DefaultButton)
},
template: `<text-button />`
})

2. HOC + render props

const DefaultButton = {
props: {
renderText: Function
},
render(h) {
return h('button', this.renderText())
}
} function wrap(comp) {
return {
render(h) {
return h(comp, {
attrs: {
renderText: () => ""
}
})
}
}
} const textButton = wrap(DefaultButton) new Vue({
render(h) {
return h(textButton)
}
})

react 的不可变,纯函数。直接导致 hooks 必须使用 const 关键字,不能是 let,这也是 hooks 的奇迹之一

const keyword 和 "不可变,纯函数" 有什么关系, 若使用 let、var, 是否不能实现hook?

请问:

  1. Hooks对Fiber更好 -> Hooks是Fiber的产物 -> 没有Fiber就不是Hooks

请问怎么用逻辑推理出这条链?

2. 对于你回答中的事实性错误, 你持什么看法?

不知道有没有正确理解你说的“移除一个属性”:

onst DefaultButton = {
props: {
renderText: Function
},
render(h) {
return h('button', this.renderText())
}
} function omitRenderText(comp, render) {
return {
render(h) {
const { renderText, ...others } = this.$attrs
return h(comp, {
attrs: {
...others,
renderText: render || renderText
}
})
}
}
} const textButton = omitRenderText(DefaultButton, () => "") new Vue({
render(h) {
return h(textButton, {
attrs: {
renderText: () => ""
}
})
}
})

如果你觉得这篇文章对你还是有很大帮助的话,不介意的话可以加下我刚刚建立的一个学习交流群,有很多相关资料和学习视频:907694362

如何评价 Vue 的 Function-based Component?的更多相关文章

  1. vue render function

    vue render function https://vuejs.org/v2/guide/render-function.html { // Same API as `v-bind:class`, ...

  2. vue render function & dataset

    vue render function & dataset https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In ...

  3. vue & arrow function error

    vue & arrow function error <template> <div class="home"> <img alt=" ...

  4. vue组件大集合 component

    vue组件分为全局组件.局部组件和父子组件,其中局部组件只能在el定义的范围内使用, 全局组件可以在随意地方使用,父子组件之间的传值问题等. Vue.extend 创建一个组件构造器 template ...

  5. Vue内置的Component标签用于动态切换组件

    html <div id="app"> <component :is="cut"></component> <butt ...

  6. vue.js组件(component)

    简介: 组件(Component)是 Vue.js 最强大的功能之一. 组件可以扩展 HTML 元素,封装可重用的代码. 组件系统让我们可以用独立可复用的小组件来构建大型应用,几乎任意类型的应用的界面 ...

  7. Vue教程:组件Component详解(六)

    一.什么是组件? 组件 (Component) 是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器为它添加特殊功 ...

  8. [Vue] Parent and Child component communcation

    By building components, you can extend basic HTML elements and reuse encapsulated code. Most options ...

  9. vue学习之组件(component)(二)

    自定义事件 父组件使用 prop 传递数据给子组件.但子组件怎么跟父组件通信呢?这个时候 Vue 的自定义事件系统就派得上用场了. 1. 使用 v-on 绑定自定义事件 每个vue实例都实现了事件接口 ...

随机推荐

  1. JavaScript Array返回值以及是否改变原数组。

    1.        push:最后一位新增://改变原数组         arr.push("123");         返回值是数组的长度:         var b =  ...

  2. 记一次 XxlRpcException:xxl-rpc request timeout at 超时问题

    事件起因 昨天有同事找我到,说他搭建的 XXL-JOB 任务调度系统不能工作了,调用总是出错(服务端返回 500)希望我能帮忙处理一下,不过说实话我也没有搭建过 XXL-JOB 的经验,但是既然同事请 ...

  3. 实现基于netty的web框架,了解一下

    上一篇写了,基于netty实现的rpc的微框架,其中详细介绍netty的原理及组件,这篇就不过多介绍 这篇实现基于netty的web框架,你说netty强不强,文中有不对的地方,欢迎大牛指正 先普及几 ...

  4. 用Python将处理数据得到的csv文件分类(按顺序)保存

    用Python中的os和numpy库对文件夹及处理数据后得到的文件进行分类保存: import numpy as np import os for m in range(699,0,-35): cur ...

  5. spring cloud(Greenwich SR)- Eureka

    spring cloud study 本次学习基于spring cloud Greenwich SR1 版本 学习要点: Spring Boot/Spring Cloud应用开发套路 加依赖 加注解 ...

  6. Java并发入门之FutureTask

    Java并发入门之FutureTask 前言: 最近遇到一个项目需要上传图片到服务器,API要求是二进制流,那就跑慢点一点点上传. 于是对多线程从没有应用过的我,决定拿多线程直接应用于代码. 应用Ex ...

  7. day34作业

    作业 查看岗位是teacher的员工姓名.年龄 select name,age from teacher where post='teacher'; 查看岗位是teacher且年龄大于30岁的员工姓名 ...

  8. 如何上传项目至GitHub

    1.下载 https://gitforwindows.org/ 2.打开Git Bash 把git绑定到GitHub 3.打开GitHub登陆后 点击settings 点击SSH and GPG ke ...

  9. MUI错误信息:系统已经存在较高版本,些安装包无法安装。

    MUI 混合开发APP 版本更新问题. 错误信息: 解决方法: manifest.json->version->code 这个值需要累加,version->name 是用于显示的,这 ...

  10. SpringCloud番外篇-服务治理之Nacos

    一.Nacos概述 Nacos是阿里巴巴开源的服务注册中心,官方文档:https://nacos.io/zh-cn/docs/what-is-nacos.html 从个人使用体验上看,nacos要比e ...