I have a HOC BoardLayoutContainer
that subscribes to a board. I pass the loading state as well, so I know if loading === false && !board
=> to show a BoardNotFound
page.
So far so good.
Now, when the board ID does exist, but the user doesn’t have permission to view it, I want to show another error. I tried to achieve this by using this.error
in the publication, and implementing an onStop
in the HOC:
export default BoardLayoutContainer = withTracker( ({ match, history }) => {
const boardId = match.params.id
const { error, setError } = useState()
const onStop = e => setError( e.message() || 'Error loading board' )
const bs = Meteor.subscribe( 'board', boardId, { onStop } )
const board = Board.first({ _id: boardId })
return { loading: !bs.ready(), error, board }
})( BoardLayout )
However, this doesn’t work:
Uncaught Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component.
Since the error is async, and there is no function for it on the handle returned by Meteor.subscribe
, I am at a loss how I should do this… Hopefully you have some ideas.