react slot component with args

how to pass args to react props child component

https://codesandbox.io/s/react-slot-component-with-args-n11d1

OK

https://codesandbox.io/s/react-slot-component-with-args-idhib

function component, pass slot child component as Function props

import React from "react";
import ReactDOM from "react-dom"; import "./styles.css"; import FunnelChart from "./FunnelChart";
import Slot from "./Slot"; function App() {
return (
<div className="App">
<FunnelChart title="xgqfrms">
<Slot />
</FunnelChart>
<hr />
<FunnelChart
title="xgqfrms"
template={title => <Slot title={title}/>}
slot={<Slot />}
/>
</div>
);
} const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
import React from "react";

const FunnelChart = (props) => {
const {
title,
children,
slot,
template,
} = props;
console.log(`template`, template);
return(
<>
<span>slot parent component</span>
<div>
{
children
}
{
slot
}
<br />
{
template && template(title)
}
{/* {
<children title={title} />
} */}
{/* {
slot(title)
} */}
</div>
</>
);
}; export {
FunnelChart,
}; export default FunnelChart;

import React from "react"; const Slot = (props) => {
const {
title,
} = props;
const color = `${title ? "green" : "red"}`;
return(
<>
<span style={{color}}>{title ? title : `default title`}</span>
</>
);
}; export {
Slot,
}; export default Slot;

props.children

https://reactjs.org/docs/composition-vs-inheritance.html


function Dialog(props) {
return (
<FancyBorder color="blue">
<h1 className="Dialog-title">
{props.title}
</h1>
<p className="Dialog-message">
{props.message}
</p>
{props.children}
</FancyBorder>
);
} class SignUpDialog extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleSignUp = this.handleSignUp.bind(this);
this.state = {login: ''};
} render() {
return (
<Dialog title="Mars Exploration Program"
message="How should we refer to you?">
<input value={this.state.login}
onChange={this.handleChange} /> <button onClick={this.handleSignUp}>
Sign Me Up!
</button>
</Dialog>
);
} handleChange(e) {
this.setState({login: e.target.value});
} handleSignUp() {
alert(`Welcome aboard, ${this.state.login}!`);
}
}

How to pass data to props.children

https://frontarm.com/james-k-nelson/passing-data-props-children/

How to pass props to {this.props.children}

https://stackoverflow.com/questions/32370994/how-to-pass-props-to-this-props-children

how-to-pass-props-from-child-to-parent-component

https://www.robinwieruch.de/react-pass-props-to-component#how-to-pass-props-from-child-to-parent-component


https://medium.com/better-programming/passing-data-to-props-children-in-react-5399baea0356

vue slot

https://www.cnblogs.com/xgqfrms/p/11218372.html

Web Components & HTML template & HTML slot

https://www.cnblogs.com/xgqfrms/p/10979925.html

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


react slot component with args的更多相关文章

  1. plupload上传控件错误exec(this.uid, component, action, args)

    plupload上传控件错误exec(this.uid, component, action, args) --undefined is not a function 原因:Flash元素隐藏后调用控 ...

  2. React & styled component

    React & styled component https://www.styled-components.com/#your-first-styled-component tagged t ...

  3. react hooks & component will unmount & useEffect & clear up

    react hooks & component will unmount & useEffect & clear up useEffect & return === u ...

  4. [React Fundamentals] Component Lifecycle - Updating

    The React component lifecycle will allow you to update your components at runtime. This lesson will ...

  5. [React Fundamentals] Component Lifecycle - Mounting Usage

    The previous lesson introduced the React component lifecycle mounting and unmounting. In this lesson ...

  6. [React Fundamentals] Component Lifecycle - Mounting Basics

    React components have a lifecycle, and you are able to access specific phases of that lifecycle. Thi ...

  7. [React] React Fundamentals: Component Lifecycle - Updating

    The React component lifecycle will allow you to update your components at runtime. This lesson will ...

  8. [React ] React Fundamentals: Component Lifecycle - Mounting Usage

    The previous lesson introduced the React component lifecycle mounting and unmounting. In this lesson ...

  9. [React] React Fundamentals: Component Lifecycle - Mounting Basics

    React components have a lifecycle, and you are able to access specific phases of that lifecycle. Thi ...

随机推荐

  1. Linux命令——netcat

    简介 netcat的简写是nc,被设计为一个简单.可靠的网络工具,主要作用如下: 1 实现任意TCP/UDP端口的侦听,nc可以作为server以TCP或UDP方式侦听指定端口 2 端口的扫描,nc可 ...

  2. 详述C++casting操作

    Casting----类型转换,也就是将数据从一种类型转换到另一种类型的操作.本文首先给出两种类型转换的方式:隐式转换和显式转换,然后简单介绍一下C语言常用的类型转换方式,最后详细叙述C++中常用的三 ...

  3. 不会开发的你也能管理好企业漏洞,开源免费工具:洞察(insight II)

    前言 公司刚开始建设安全管理时,都是从一片混沌开始的,资源总是不够的,我们每个做安全的人员,又要会渗透,又要抓制度,还得管理各种漏洞.在管理楼栋是,我相信大家都遇到过以下几个问题: 漏洞提交太多,自己 ...

  4. Ceph对象存储 S3

    ceph对象存储 作为文件系统的磁盘,操作系统不能直接访问对象存储.相反,它只能通过应用程序级别的API访问.ceph是一种分布式对象存储系统,通过ceph对象网关提供对象存储接口,也称为RADOS网 ...

  5. Effective Java读书笔记--创建和销毁对象

    1.优先考虑用静态工厂方法代替构造器2.遇到多个构造器参数时要考虑使用构建器Builder解决参数过多,不可变类型.私有构造方法,静态类的构造方法提供必要参数,剩下可选.new xxx.build() ...

  6. Watering Grass(贪心算法)

    给定一条草坪.草坪上有n个喷水装置.草坪长l米宽w米..n个装置都有每个装置的位置和喷水半径..要求出最少需要几个喷水装置才能喷满草坪..喷水装置都是装在草坪中间一条水平线上的. n sprinkle ...

  7. spoj687 REPEATS - Repeats (后缀数组+rmq)

    A string s is called an (k,l)-repeat if s is obtained by concatenating k>=1 times some seed strin ...

  8. Gym 2009-2010 ACM ICPC Southwestern European Regional Programming Contest (SWERC 2009) A. Trick or Treat (三分)

    题意:在二维坐标轴上给你一堆点,在x轴上找一个点,使得该点到其他点的最大距离最小. 题解:随便找几个点画个图,不难发现,答案具有凹凸性,有极小值,所以我们直接三分来找即可. 代码: int n; lo ...

  9. 一文弄懂使用Jmeter来进行性能测试

    该文章是基于上一次文章的 软件测试漫谈(web测试,自动化测试,Jmeter) 的续篇, 主要是详细讲解 Jmeter 的入门教程. 因为上次的文章只是简单地讲解了 Jmeter 的使用和一些概念,所 ...

  10. ES中文分词器安装以及自定义配置

    之前我们创建索引,查询数据,都是使用的默认的分词器,分词效果不太理想,会把text的字段分成一个一个汉字,然后搜索的时候也会把搜索的句子进行分词,所以这里就需要更加智能的分词器IK分词器了. ik分词 ...