marmelab / marmelab/react-admin

Title component usage does not override existing title

Open
#6,976 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
26.9k
Forks
5.5k
Avg merge
2d 3h
Merged PRs (30d)
19

Description

**Is your feature request related to a problem? Please describe.**
I have a page that conditionally renders child components. The page uses react-admin's `Title` component to set a title. In most cases, when child component is rendered, `Title` should stay the same as in parent component; however, in some conditions, we want to be able to override page's title from within child.

Today, if both parent and child component have `Title` rendered, react-admin will just append Title2 to Title1 (will show `Title1Title2`)

```js
function ParentComponent = (props) => {
const conditional = props.display? : null
return (


Welcome to ParentComponent
{conditional}
</Fragment>
)
}

function ConditionalChild = () => {
const status = fetch_status()
if (status===0)
return (
<Fragment>
<Title title="Title2">
Status 0
</Fragment>
)
else
return (
<Fragment>
Other status
</Fragment>
)
}
```

**Describe the solution you'd like**
if a component or its children have multiple `Title` calls, the last call should win (similar to what react-helmet does while setting page title)

**Describe alternatives you've considered**
No clear solution found

**Additional context**
none

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the react-admin Title component entry point and trace how multiple rendered Title components contribute to the document title. Reproduce the parent and conditional-child example, then verify that the most recently rendered Title replaces rather than appends to the existing title.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.