Skip to content

Flatlist: Warning when height not explicitly set: Error in parsing value for ‘height’. Declaration dropped. #52538

@benmarten

Description

@benmarten

Description

When not explicitly setting the height of the renderItem of FlatList, a warning is thrown: Error in parsing value for ‘height’. Declaration dropped. - is there anyway to avoid this warning or is there a better way to handle this for content that has dynamic height? Thanks

Steps to reproduce

const renderItem = ({ item }) => (
  <View className="p-4 mx-4 mb-3 rounded-lg border border-gray-200">
    <Text>{item.title}</Text>
    <Text>{item.description}</Text>
  </View>
)

export default function HomeScreen() {
  return (
    <View style={styles.container}>
      <ThemedView className="px-4 pb-4">
        <ThemedText type="title">Simple List</ThemedText>
      </ThemedView>
      <FlatList
        data={data}
        renderItem={renderItem}
        keyExtractor={(item) => item.id}
        showsVerticalScrollIndicator={false}
        style={styles.list}
      />
    </View>
  )
}

When explicitly adding:

        getItemLayout={(data, index) => ({
          length: 80,
          offset: 80 * index,
          index,
        })}

Warning is not thrown.

React Native Version

0.79.3

Affected Platforms

Runtime - Web

Output of npx @react-native-community/cli info

info Fetching system and libraries information...
System:
  OS: macOS 15.5
  CPU: (8) arm64 Apple M2
  Memory: 154.64 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.17.0
    path: /usr/local/bin/node
  Yarn: Not Found
  npm:
    version: 10.9.2
    path: /usr/local/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.5
      - iOS 18.5
      - macOS 15.5
      - tvOS 18.5
      - visionOS 2.5
      - watchOS 11.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.3 AI-243.26053.27.2432.13536105
  Xcode:
    version: 16.4/16F6
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 21.0.7
    path: /opt/homebrew/opt/openjdk@21/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.3
    wanted: 0.79.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

info React Native v0.80.1 is now available (your project is running on v0.79.3).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.80.1
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.79.3&to=0.80.1
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".

Stacktrace or Logs

Error in parsing value for ‘height’.  Declaration dropped. 8 localhost:8081:1:1

MANDATORY Reproducer

https://github.com/benmarten/flatlist-warn

Screenshots and Videos

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions