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. cookie中的domain和path

    div.example { background-color: rgba(229, 236, 243, 1); color: rgba(0, 0, 0, 1); padding: 0.5em; mar ...

  2. CSS居中的常用方式以及优缺点

    前言 居中是页面开发中经常遇到的问题. 使用合适的.简单的.兼容性好的居中方式是我们页面仔在整个工作生涯中都要面对的问题. text-align:center 来看这个例子,一张图片和文字进行居中.如 ...

  3. loj10170

    在 n×n 的棋盘上放 k 个国王,国王可攻击相邻的 8 个格子,求使它们无法互相攻击的方案总数. -------------------------------------------------- ...

  4. 基于GTID恢复误篡改数据

    问题描述:创建测试库和测试表,先update数据,在delete数据,在update数据,通过gtid查找两次update的值. 参考文档:https://baijiahao.baidu.com/s? ...

  5. nginx及其常用实践方案

    nginx及其常用实践方案 1.概述 1.1 什么是nginx? 1.2 什么是反向代理? 2.nginx常用命令 3.ningx配置实践 3.1 nginx.conf基础配置项 3.2 http 反 ...

  6. c++复习笔记(2)

    1. 类与对象 类的声明与结构,数据成员和成员函数. 成员函数可以在类外被定义.但是必须在类内声明. 封装:protect--允许类成员和派生类成员访问. 构造函数之外,还有一种初始化类成员的方法:参 ...

  7. swap交换2变量

    #define swap(x,y) {(x)=(x)+(y); (y)=(x)-(y); (x)=(x)-(y);} void swap(int i, int offset){ int temp; t ...

  8. poj 1511-- Invitation Cards (dijkstra+优先队列)

    刚开始想复杂了,一直做不出来,,,其实就是两遍dijkstra+优先队列(其实就是板子题,只要能有个好的板子,剩下的都不是事),做出来感觉好简单...... 题意:有n个车站和n个志愿者,早上每个志愿 ...

  9. java中static修改成员变量和函数和其他使用

    一.通过static修饰的成员变量初始化只会初始化一次 //静态变量初始化只会初始化一次 public class zuishuai { public static void main(String[ ...

  10. 迪杰斯特拉+拆点 Deliver the Cake - HDU 6805

    题意: t组输入,给你n个点m条边.你需要输出从s点到t点的最短距离,然后是m条边,每条边输入信息为: a,b,c 表示从a点到b点的一个无向边长度为c 每一个点会有一个属性L.R或M 如果a和b一个 ...