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 发布文章使用:只允许注册用户才可以访问!


最新文章

  1. gd库
  2. MySQL慢查询日志总结
  3. SQL Server里的INTERSECT ALL
  4. Meteor错误:TypeError: Meteor.userId is not a function
  5. thinkphp中session跨域问题
  6. WF系列——工作流基本知识
  7. jQuery源码研究——怎么看源码
  8. 配置phpstorm自动上传代码
  9. 322. Coin Change零钱兑换
  10. js实现input的赋值
  11. 标准C语言实现基于TCP/IP协议的文件传输
  12. xcopy命令总结
  13. JAVA中通过Hibernate-Validation进行参数验证
  14. MariaDB基础命令
  15. MBR:主引导记录:
  16. 2018.08.19 NOIP模拟 change(简单模拟)
  17. Eclipse 中java跨工程调用类
  18. [Grunt] Watch &amp;&amp; grunt-contrib-watch
  19. 微信小程序页面跳转后js定时器没有销毁的问题
  20. LWIP内存管理

热门文章

  1. WPF和MVVM的结合使用方法,不可错过
  2. HttpClientUtils:Http请求工具类
  3. Spark DataSource Option 参数
  4. trunk
  5. 武装你的WEBAPI-OData常见问题
  6. linux(3) 处理目录的常用命令
  7. SCZ 20170812 T2 MFS
  8. Codeforces Round #655 (Div. 2) A. Omkar and Completion
  9. SCZ 20170812 T1 HKJ
  10. HDOJ 1348 基本二维凸包问题