Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

Commit 4998a51

Browse files
committed
AG-2178 Add docs and example on how to use Context API with React
1 parent 518a95e commit 4998a51

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

src-examples/simpleReduxDynamicComponentExample/GridComponent.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {connect} from "react-redux";
66

77
import PriceRenderer from "./PriceRenderer";
88

9+
const ThemeContext = React.createContext('light');
10+
911
/*
1012
* This component serves to display the row data (provided by redux)
1113
*/

src-examples/simpleReduxDynamicComponentExample/PriceRenderer.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, {Component} from "react";
22
import {connect} from "react-redux";
33

4+
import FontContext from './fontContext'
5+
46
class PriceRenderer extends Component {
57
constructor(props) {
68
super(props);
@@ -18,7 +20,9 @@ class PriceRenderer extends Component {
1820

1921
render() {
2022
return (
21-
<span>{this.props.currencySymbol}{this.state.convertedValue}</span>
23+
<FontContext.Consumer>
24+
{fontWeight => <span style={{fontWeight}}> {this.props.currencySymbol}{this.state.convertedValue}</span> }
25+
</FontContext.Consumer>
2226
);
2327
}
2428

@@ -36,5 +40,5 @@ export default connect(
3640
},
3741
null,
3842
null,
39-
{ withRef: true } // must be supplied for react/redux when using GridOptions.reactNext
43+
{withRef: true} // must be supplied for react/redux when using GridOptions.reactNext
4044
)(PriceRenderer);

src-examples/simpleReduxDynamicComponentExample/SimpleReduxExample.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import GridComponent from "./GridComponent";
99

1010
import gridData from "./gridDataReducer";
1111

12+
import FontContext from './fontContext'
13+
1214
let store = createStore(gridData);
1315

1416
/*
@@ -26,7 +28,9 @@ export default class SimpleReduxExample extends Component {
2628
<div>
2729
<h1>Simple Redux Example using Connected React Components</h1>
2830
<HeaderComponent/>
29-
<GridComponent/>
31+
<FontContext.Provider value="bold">
32+
<GridComponent/>
33+
</FontContext.Provider>
3034
</div>
3135
</Provider>
3236
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import React from "react";
2+
3+
export default React.createContext('normal');

0 commit comments

Comments
 (0)