Guest User

Untitled

a guest
Oct 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <Pie>
  2. <OtherComp>
  3. <div>
  4. <Slice>
  5. </Slice>
  6. <Slice>
  7. </Slice>
  8. </div>
  9. </OtherComp>
  10. </Pie>
  11.  
  12. class Pie extends Component {
  13.  
  14. render() {
  15. const { children } = this.props;
  16.  
  17. // тут надо передать параметры color
  18. // которые компонент Slice ожидает
  19.  
  20. return (
  21. <g>
  22. {children}
  23. </g>
  24. );
  25. }
  26. }
  27.  
  28.  
  29.  
  30.  
  31. class Slice extends Component {
  32.  
  33. render() {
  34. const { color } = this.props;
  35.  
  36. return (
  37. <line color={color}></line>
  38. );
  39. }
  40. }
  41.  
  42. import React, {Component} from 'react';
  43.  
  44. export const ThemeContext = React.createContext('light');
  45.  
  46. class Pie extends Component {
  47.  
  48. render() {
  49. const {children} = this.props;
  50. // тут надо передать параметры color
  51. // которые компонент Slice ожидает
  52. const color = '#FFF'
  53. return (
  54. <ThemeContext.Provider value={color}>
  55. <g>
  56. {children}
  57. </g>
  58. </ThemeContext.Provider>);
  59. }
  60. }
  61. export default Pie;
  62.  
  63. import React, {Component} from 'react';
  64. import { ThemeContext } from '../Pie'
  65.  
  66. export default class Slice extends Component {
  67. render() {
  68. return (
  69. <ThemeContext.Consumer>
  70. {color=> <line color={color}>{color}</line> }
  71. </ThemeContext.Consumer>
  72. );
  73. }
  74. }
  75.  
  76. <Pie>
  77. <OtherComp>
  78. <div>
  79. <Slice>
  80. </Slice>
  81. <Slice>
  82. </Slice>
  83. </div>
  84. </OtherComp>
  85. </Pie>
Add Comment
Please, Sign In to add comment