Question: I've set my mapping up as follows:

```
CreateMap<SourceClass, DestinationClass>().ForMember(destinationMember => destinationMember.Provider,
                memberOptions => memberOptions.MapFrom(src => src.Providers.FirstOrDefault()));

```

Where I'm mapping from a List in my SourceClass to a string in my destination class.

My question is, how can I handle the case where "Providers" is null?

I've tried using:

`src?.Providers?.FirstOrDefault()`

but I get an error saying I can't use null propagators in a lambda.

I've been reading up on Automapper and am still unsure if AM automatically handles the null case or not. I tried to build the expression tree, but was not able to see any information that provided additional informations.

If it helps, I'm using automapper v 6.1.1.

Answer: 
Like what @goto1 mentioned in a comment, you may create a custom hook to use for a cleaner and reusable look. Here's my take on a custom hook called `useCbOnce` which calls any event callback once:

```
const useCbOnce = (cb) => {
    const [called, setCalled] = useState(false);

    // Below can be wrapped in useCallback whenever re-renders becomes a problem
    return (e) => {
        if (!called) {
            setCalled(true);
            cb(e);
        }
    }
}

const MyForm = (props) => {
    const handleSubmit = useCbOnce((e) => {
        e.preventDefault()
        console.log('submitted!')
    });
    return <form onSubmit={handleSubmit}>...</form>;
}

```
Here's an example that lets you customize what action happens on submit, but always prevents the default and only calls the action once.

```js
function useSubmitAction(action=null, dependencies = [action]) {
  const [submitted, setSubmitted] = React.useState(false)
  return React.useCallback(function (event, ...rest) {
    event.preventDefault()
    if (submitted) return
    setSubmitted(true)
    if (action) action(event, ...rest)
  }, dependencies)
}

function FooForm(props) {
  const onSubmit = useSubmitAction((e) => console.log('submitting event type', e.type))
  return (<form onSubmit={ onSubmit }>
    <button type="submit">Submit</button>
  </form>)
}

ReactDOM.render(<FooForm />, document.getElementById('app'))
```

```html
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<div id="app" />
```

Note that you may want to set the `submitted` state to true after you call the action, so that if errors occur then submit doesn't get set to true. But it depends on your use case.