From 46215fafb6b3122f103a10e01443c942c31ee1ff Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 13 Oct 2018 12:42:58 +0300 Subject: [PATCH 1/6] Add MappedList --- snippets/MappedList.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 snippets/MappedList.md diff --git a/snippets/MappedList.md b/snippets/MappedList.md new file mode 100644 index 000000000..bcec0f75f --- /dev/null +++ b/snippets/MappedList.md @@ -0,0 +1,31 @@ +### MappedList + +Renders a list of elements from an array of data. + +Use the value of the `isOrderedList` prop to conditionally render a `
    ` or `
+ ) : ( -}; + ); +} ``` ```jsx const names = ['John', 'Paul', 'Mary']; ReactDOM.render(, document.getElementById('root')); const users = [ { id: 8, value: 'john' }, { id: 3, value: 'paul' }]; -ReactDOM.render(, document.getElementById('root')); +ReactDOM.render( + , + document.getElementById('root') +); ``` From 5b077a0c77352d29c02246ab297ccaa10d3af0d0 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 17 Oct 2018 10:13:11 +0300 Subject: [PATCH 3/6] Update MappedList.md --- snippets/MappedList.md | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/snippets/MappedList.md b/snippets/MappedList.md index ca7eba5a6..17b9bba5f 100644 --- a/snippets/MappedList.md +++ b/snippets/MappedList.md @@ -8,20 +8,11 @@ Use `Array.prototype.map` to render every item in `data` as a `
  • ` element and Omit the `isOrderedList` prop to render a `
      ` list by default. ```jsx -function MappedList(props) { - return props.isOrderedList ? ( -
        - {props.data.map((v, i) => ( -
      1. {v.value ? v.value : v}
      2. - ))} -
      - ) : ( -
        - {props.data.map((v, i) => ( -
      • {v.value ? v.value : v}
      • - ))} -
      - ); +function MappedList({ isOrderedList, data}) { + const list = data.map((v, i) => ( +
    • {v.value ? v.value : v}
    • + )); + return isOrderedList ?
        {list}
      :
        {list}
      ; } ``` From fc726d85a676d39f73169309fe851a62ea7d48a2 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 17 Oct 2018 10:13:33 +0300 Subject: [PATCH 4/6] Update MappedList.md --- snippets/MappedList.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/MappedList.md b/snippets/MappedList.md index 17b9bba5f..b3b1c9c2a 100644 --- a/snippets/MappedList.md +++ b/snippets/MappedList.md @@ -8,7 +8,7 @@ Use `Array.prototype.map` to render every item in `data` as a `
    • ` element and Omit the `isOrderedList` prop to render a `
        ` list by default. ```jsx -function MappedList({ isOrderedList, data}) { +function MappedList({ isOrderedList, data }) { const list = data.map((v, i) => (
      • {v.value ? v.value : v}
      • )); From 8b54ea0cda1cf72f9753b8df9a73416b0c41f37f Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 17 Oct 2018 20:31:22 +0300 Subject: [PATCH 5/6] Update MappedList.md --- snippets/MappedList.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/snippets/MappedList.md b/snippets/MappedList.md index b3b1c9c2a..2d79ced35 100644 --- a/snippets/MappedList.md +++ b/snippets/MappedList.md @@ -2,17 +2,17 @@ Renders a list of elements from an array of data. -Use the value of the `isOrderedList` prop to conditionally render a `
          ` or `
            ` list. +Use the value of the `isOrdered` prop to conditionally render a `
              ` or `
                ` list. Use `Array.prototype.map` to render every item in `data` as a `
              • ` element and give it a `key`. `data` can either be an array of objects with the `id` and `value` properties or an array of primitives. -Omit the `isOrderedList` prop to render a `
                  ` list by default. +Omit the `isOrdered` prop to render a `
                    ` list by default. ```jsx -function MappedList({ isOrderedList, data }) { +function MappedList({ isOrdered, data }) { const list = data.map((v, i) => (
                  • {v.value ? v.value : v}
                  • )); - return isOrderedList ?
                      {list}
                    :
                      {list}
                    ; + return isOrdered ?
                      {list}
                    :
                      {list}
                    ; } ``` @@ -21,7 +21,7 @@ const names = ['John', 'Paul', 'Mary']; ReactDOM.render(, document.getElementById('root')); const users = [ { id: 8, value: 'john' }, { id: 3, value: 'paul' }]; ReactDOM.render( - , + , document.getElementById('root') ); ``` From 57ec6d4b6886eac4ace74a63206a24b9e0c2f1cc Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 29 Nov 2018 12:12:24 +0200 Subject: [PATCH 6/6] Simplify MappedList and rename to DataList --- snippets/DataList.md | 26 ++++++++++++++++++++++++++ snippets/MappedList.md | 31 ------------------------------- 2 files changed, 26 insertions(+), 31 deletions(-) create mode 100644 snippets/DataList.md delete mode 100644 snippets/MappedList.md diff --git a/snippets/DataList.md b/snippets/DataList.md new file mode 100644 index 000000000..99ee8980b --- /dev/null +++ b/snippets/DataList.md @@ -0,0 +1,26 @@ +### DataList + +Renders a list of elements from an array of primitives. + +Use the value of the `isOrdered` prop to conditionally render a `
                      ` or `
                        ` list. +Use `Array.prototype.map` to render every item in `data` as a `
                      • ` element, give it a `key` produced from the concatenation of the its index and value. +Omit the `isOrdered` prop to render a `
                          ` list by default. + +```jsx +function DataList({ isOrdered, data }) { + const list = data.map((val, i) => ( +
                        • {val}
                        • + )); + return isOrdered ?
                            {list}
                          :
                            {list}
                          ; +} +``` + +```jsx +const names = ['John', 'Paul', 'Mary']; +ReactDOM.render(, document.getElementById('root')); +ReactDOM.render(, document.getElementById('root')); +``` + + + + diff --git a/snippets/MappedList.md b/snippets/MappedList.md deleted file mode 100644 index 2d79ced35..000000000 --- a/snippets/MappedList.md +++ /dev/null @@ -1,31 +0,0 @@ -### MappedList - -Renders a list of elements from an array of data. - -Use the value of the `isOrdered` prop to conditionally render a `
                            ` or `
                              ` list. -Use `Array.prototype.map` to render every item in `data` as a `
                            • ` element and give it a `key`. -`data` can either be an array of objects with the `id` and `value` properties or an array of primitives. -Omit the `isOrdered` prop to render a `
                                ` list by default. - -```jsx -function MappedList({ isOrdered, data }) { - const list = data.map((v, i) => ( -
                              • {v.value ? v.value : v}
                              • - )); - return isOrdered ?
                                  {list}
                                :
                                  {list}
                                ; -} -``` - -```jsx -const names = ['John', 'Paul', 'Mary']; -ReactDOM.render(, document.getElementById('root')); -const users = [ { id: 8, value: 'john' }, { id: 3, value: 'paul' }]; -ReactDOM.render( - , - document.getElementById('root') -); -``` - - - -