Skip to content

Commit

Permalink
Rename HeadCollector to HeadProvider (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Jul 9, 2018
1 parent 2f0badf commit 3ab9902
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 42 deletions.
17 changes: 0 additions & 17 deletions .eslintrc

This file was deleted.

13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
parser: 'babel-eslint',
plugins: ['prettier'],
extends: ['airbnb', 'prettier', 'prettier/react'],
env: {
browser: true,
jest: true,
},
rules: {
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
'react/forbid-prop-types': 0,
},
};
18 changes: 9 additions & 9 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"dist/index.umd.js": {
"bundled": 5916,
"minified": 2673,
"gzipped": 1119
"bundled": 5857,
"minified": 2672,
"gzipped": 1117
},
"dist/index.cjs.js": {
"bundled": 4328,
"minified": 2646,
"gzipped": 945
"bundled": 4271,
"minified": 2642,
"gzipped": 942
},
"dist/index.esm.js": {
"bundled": 3941,
"minified": 2330,
"gzipped": 856,
"bundled": 3885,
"minified": 2327,
"gzipped": 853,
"treeshaked": {
"rollup": {
"code": 392,
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ npm i react-head

## How it works

1. On the server, you wrap your App in `<HeadCollector />` with a given `headTags[]` array
1. On the server, you wrap your App in `<HeadProvider />` with a given `headTags[]` array
1. Then call `renderToString(headTags)` and include in the `<head />` block of your server template
1. To insert head tags within your app, just render `<HeadTag />` components as often as needed.

Expand All @@ -26,22 +26,22 @@ On the server, the tags are collected in the `headTags[]` array, and then on the
### Server setup

Wrap your app with `<HeadCollector />` on the server with a given `headTags[]` array to pass down as part of your server-rendered payload.
Wrap your app with `<HeadProvider />` on the server with a given `headTags[]` array to pass down as part of your server-rendered payload.

```js
import * as React from 'react';
import { renderToString } from 'react-dom/server';
import { HeadCollector } from 'react-head';
import { HeadProvider } from 'react-head';
import App from './App';

// ... within the context of a request ...

const context = {};
const headTags = [];
const app = renderToString(
<HeadCollector headTags={headTags}>
<HeadProvider headTags={headTags}>
<App />
</HeadCollector>
</HeadProvider>
);

res.send(`
Expand Down
4 changes: 2 additions & 2 deletions src/HeadCollector.js → src/HeadProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as React from 'react';
import PropTypes from 'prop-types';
import { Provider } from './headTagsContext';

export default class HeadCollector extends React.Component {
export default class HeadProvider extends React.Component {
static propTypes = {
headTags: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types
headTags: PropTypes.array.isRequired,
children: PropTypes.node.isRequired,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as React from 'react';
import { render } from 'enzyme';
import { HeadCollector, HeadTag } from '../';
import { HeadProvider, HeadTag } from '../';

describe('HeadCollector', () => {
describe('HeadProvider', () => {
it('adds HeadTags to given array from component tree', () => {
const arr = [];
render(
<HeadCollector headTags={arr}>
<HeadProvider headTags={arr}>
<div>
<HeadTag tag="tag1" name="name1" another="value1" />
<HeadTag tag="tag2" test="test2" third="value2" />
</div>
</HeadCollector>
</HeadProvider>
);

expect(arr.length).toBe(2);
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/HeadTags.node.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { HeadCollector, HeadTag, Title, Style, Meta, Link } from '../';
import { HeadProvider, HeadTag, Title, Style, Meta, Link } from '../';

describe('HeadTag during server rendering', () => {
const arr = [];
const globalCss = `p {
color: #121212;
}`;
const markup = renderToStaticMarkup(
<HeadCollector headTags={arr}>
<HeadProvider headTags={arr}>
<div>
Yes render
<HeadTag tag="test" content="testing tag">
Expand All @@ -19,7 +19,7 @@ describe('HeadTag during server rendering', () => {
<Link href="index.css" />
<Meta charset="utf-8" />
</div>
</HeadCollector>,
</HeadProvider>,
{
context: {
reactHeadTags: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`HeadCollector adds HeadTags to given array from component tree 1`] = `
exports[`HeadProvider adds HeadTags to given array from component tree 1`] = `
Array [
<tag1
another="value1"
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export const Meta = props => <HeadTag tag="meta" {...props} />;

export const Link = props => <HeadTag tag="link" {...props} />;

export { default as HeadCollector } from './HeadCollector';
export { default as HeadProvider } from './HeadProvider';

export { HeadTag };

0 comments on commit 3ab9902

Please sign in to comment.