Skip to content

Commit 09849dd

Browse files
committed
Update example
1 parent 282773c commit 09849dd

File tree

4 files changed

+13
-37
lines changed

4 files changed

+13
-37
lines changed

example/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import React, { PropTypes } from 'react';
22
import { render } from 'react-dom';
3+
import reactReplaceString from 'react-replace-string';
34

4-
import reactReplaceString from '../';
5-
6-
const Highlight = React.createClass({
5+
const HighlightNumbers = React.createClass({
76
propTypes: {
87
content: PropTypes.string.isRequired,
98
},
109

1110
render() {
1211
return (
1312
<div>
14-
{reactReplaceString(this.props.content, )
15-
<span className='highlight'>{x}</span>
16-
}
13+
{reactReplaceString(this.props.content, /(\d+)/g, (match, i) => (
14+
<span key={i} style={{ color: 'red' }}>{match}</span>
15+
))}
1716
</div>
1817
);
1918
},
@@ -23,4 +22,4 @@ const Highlight = React.createClass({
2322
const content = `Hey my number is 555-555-5555.`;
2423

2524
// Render the app
26-
render(<Highlight content={content} />, document.getElementById('root'));
25+
render(<HighlightNumbers content={content} />, document.getElementById('root'));

example/package.json

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,22 @@
99
"license": "MIT",
1010
"homepage": "",
1111
"devDependencies": {
12-
"autoprefixer-loader": "^3.1.0",
13-
"axis": "^0.5.2",
1412
"babel": "^5.8.34",
1513
"babel-core": "^5.4.7",
1614
"babel-eslint": "^4.1.6",
1715
"babel-loader": "^5.1.2",
1816
"babel-plugin-react-transform": "^1.1.1",
19-
"css-loader": "^0.23.0",
20-
"eslint": "^1.10.3",
21-
"eslint-config-airbnb": "^2.1.1",
22-
"eslint-plugin-react": "^3.12.0",
2317
"express": "^4.13.3",
24-
"extract-text-webpack-plugin": "^0.9.1",
25-
"file-loader": "^0.8.5",
26-
"history": "^1.17.0",
27-
"normalize.css": "^3.0.3",
2818
"react": "^0.14.3",
2919
"react-dom": "^0.14.3",
30-
"react-router": "^1.0.3",
3120
"react-static-webpack-plugin": "^0.3.0",
3221
"react-transform-catch-errors": "^1.0.0",
3322
"react-transform-hmr": "^1.0.1",
3423
"redbox-react": "^1.2.0",
35-
"rimraf": "^2.4.4",
36-
"rupture": "^0.6.1",
37-
"style-loader": "^0.13.0",
38-
"stylus-loader": "^1.4.2",
39-
"url-loader": "^0.5.7",
4024
"webpack": "^1.12.9",
4125
"webpack-dev-middleware": "^1.4.0",
42-
"webpack-hot-middleware": "^2.6.0"
26+
"webpack-hot-middleware": "^2.6.0",
27+
"react-replace-string": "*"
4328
},
4429
"dependencies": {}
4530
}

example/server.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,18 @@ import { renderToStaticMarkup } from 'react-dom/server';
88
import express from 'express';
99
import webpack from 'webpack';
1010

11-
import config from './webpack.config.dev.js';
11+
import config from './webpack.config.js';
1212

13-
const Html = ({
14-
title = 'Rainbow Unicorns',
15-
bundle = '/app.js',
16-
body = '',
17-
favicon = '',
18-
stylesheet = '',
19-
}) => (
13+
const Html = ({ bundle = '/app.js' }) => (
2014
<html lang='en'>
2115
<head>
2216
<meta charSet='utf-8' />
2317
<meta httpEquiv='X-UA-Compatible' content='IE=edge' />
2418
<meta name='viewport' content='width=device-width, initial-scale=1' />
25-
<title>{title}</title>
26-
{favicon && <link rel='shortcut icon' href={favicon} />}
27-
{stylesheet && <link rel='stylesheet' href={stylesheet} />}
19+
<title>React String Replace Example</title>
2820
</head>
2921
<body>
30-
<div id='root' dangerouslySetInnerHTML={{ __html: body }} />
22+
<div id='root' />
3123
<script src={bundle} />
3224
</body>
3325
</html>

example/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
entry: {
1919
app: [
2020
'webpack-hot-middleware/client?path=' + HMR_HOST,
21-
'./client/index.js',
21+
'./index.js',
2222
],
2323
},
2424

0 commit comments

Comments
 (0)