How do you conditionally show fields in “Show” component in react-admin?

前端 未结 1 694
长情又很酷
长情又很酷 2020-12-19 19:12

Some fields I want to only show if they have a value. I would expect to do this like so:


  
    { props.reco         


        
相关标签:
1条回答
  • 2020-12-19 19:43

    We need to update our documentation about this. In the mean time, you can find informations about how to achieve that in the upgrade guide: https://github.com/marmelab/react-admin/blob/master/UPGRADE.md#aor-dependent-input-was-removed

    Here's an example:

    import { ShowController, ShowView, SimpleShowLayout, TextField } from 'react-admin';
    
    const UserShow = props => (
        <ShowController {...props}>
            {controllerProps => 
                <ShowView {...props} {...controllerProps}>
                    <SimpleShowLayout>
                        <TextField source="username" />
                        {controllerProps.record && controllerProps.record.hasEmail && 
                            <TextField source="email" />
                        }
                    </SimpleShowLayout>
                </ShowView>
            }
        </ShowController>
    );
    
    0 讨论(0)
提交回复
热议问题