Skip to content

Commit

Permalink
fix estimatedItemSize bug
Browse files Browse the repository at this point in the history
  • Loading branch information
deguchi committed Apr 5, 2022
1 parent a62089c commit 314d1b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
13 changes: 7 additions & 6 deletions example/component/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class App extends Component<Props, State> {
constructor(props: Props) {
super(props)
this.state = {
items: props.items,
items: [],
itemHeight: 200,
width: 100,
height: 0,
Expand Down Expand Up @@ -70,6 +70,10 @@ class App extends Component<Props, State> {
key: 'isbn', value: isbn
}})
}

fetch('https://bookdata-fair.calil.dev/all.json').then((r) => r.json()).then((r) => {
this.setState({items: r})
})
}

onChange(state: State) {
Expand All @@ -83,11 +87,8 @@ class App extends Component<Props, State> {
}

render() {

if (!this.state.items) return null


return (
console.log(this.state.items)
return (
<div>
{this.state.rowRatios ? (
<React.Fragment>
Expand Down
12 changes: 5 additions & 7 deletions example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import React from 'react';
import ReactDOM from 'react-dom';
import App from '../example/component/App';

fetch('https://bookdata-fair.calil.dev/all.json').then((r) => r.json()).then((r) => {
ReactDOM.render(
<React.StrictMode>
<App items={r} />
</React.StrictMode>,
document.getElementById('root'));
})
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root'));
4 changes: 4 additions & 0 deletions src/Hiradumi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ interface Props {

const Hiradumi = (props: Props) => {

// itemsがない場合は、estimatedItemSizeが出せないので、なにも処理しない
// VariableSizeListのestimatedItemSizeは、最初の1回しか処理されないため
if (props.items===undefined || props.items===null || props.items.length===0) return null

let Items = props.items.map( item => ({...item}))
let Rows: any[] = []
let HiradumiDiv: any = null
Expand Down

0 comments on commit 314d1b3

Please sign in to comment.