Skip to content

Commit 12532b0

Browse files
author
Igor Canedo
committed
fixing viewafterlist without a key
1 parent d474033 commit 12532b0

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

sample/__tests__/getBlocks.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ describe('return specific component based on type', () => {
5959
const bodyData = { blocks: [{ type: 'atomic' }] };
6060
const atomicHandler = item => item;
6161
const result = getBlocks({ contentState: bodyData, atomicHandler });
62-
expect(result[0][1].type).toBe('atomic');
62+
expect(result[0].type).toBe('atomic');
63+
});
64+
65+
it('atomicHandler function when type atomic between lists', () => {
66+
const bodyData = { blocks: [
67+
{ type: 'ordered-list-item' }, { type: 'atomic' }, { type: 'ordered-list-item' },
68+
] };
69+
const atomicHandler = item => item;
70+
const result = getBlocks({ contentState: bodyData, atomicHandler });
71+
expect(result[1][1].type).toBe('atomic');
6372
});
6473

6574
it('array of null when type is invalid', () => {

src/getBlocks.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const getBlocks = (params: ParamsType): ?Array<*> => {
6565
if (myCounter.count >= 0) {
6666
if (myCounter.count > 0) {
6767
myCounter.count = 0;
68-
return <ViewAfterList />;
68+
return <ViewAfterList key={generateKey()} />;
6969
}
7070
return null;
7171
}
@@ -74,7 +74,7 @@ const getBlocks = (params: ParamsType): ?Array<*> => {
7474
if (myCounter['unordered-list-item'].count > 0 || myCounter['ordered-list-item'].count > 0) {
7575
myCounter['unordered-list-item'].count = 0;
7676
myCounter['ordered-list-item'].count = 0;
77-
return <ViewAfterList />;
77+
return <ViewAfterList key={generateKey()} />;
7878
}
7979

8080
return null;
@@ -115,10 +115,14 @@ const getBlocks = (params: ParamsType): ?Array<*> => {
115115
}
116116

117117
case 'atomic': {
118-
const atomicView = [];
119-
atomicView.push(checkCounter(counters));
120-
atomicView.push(atomicHandler(item));
121-
return atomicView;
118+
const separator = checkCounter(counters);
119+
if (separator) {
120+
const atomicView = [];
121+
atomicView.push(separator);
122+
atomicView.push(atomicHandler(item));
123+
return atomicView;
124+
}
125+
return atomicHandler(item);
122126
}
123127

124128
case 'blockquote': {

0 commit comments

Comments
 (0)