是否可以让父组件的 props 在子组件中可用而不将它们传递下来?
我正在尝试实现一个提供程序模式,以便访问其子组件中的所有提供程序道具。前任:
假设下面的提供程序 compFetchProvider 将自行获取数据和主题道具,并且当它包含任何子组件时,我也想访问子组件中的道具“数据”和“主题”。我们怎样才能实现它呢?
class FetchProvider
{
proptypes= {
data: PropTypes.shape({}),
theme: PropTypes.shape({})
}
render()
{
// do some
}
mapStateToProps()
{
return {data, theme};
}
}
class ChildComponent
{
proptypes= {
name: PropTypes.shape({})
}
render()
{
const{data, them} = this.props; // is this possible here?
// do some
}
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用上面的组件,如下所示。
<FetchProvider>
<ChildComponent name="some value"/> //how can we access parent component props here? without passing them down
<FetchProvider/>
Run Code Online (Sandbox Code Playgroud) 我有一个 Typescript 库,正在从 React 应用程序中使用。我想导入带有子路径的 TS 库内容,例如
import {base} from "my-lib"
import {foo} from "my-lib/path1"
import {bar} from "my-lib/path2"
Run Code Online (Sandbox Code Playgroud)
我遇到了Github 问题exports,其中指出Typescript尚不支持此功能(在 package.json 中)。我正在使用 Typescript 4.3。
在同一线程中发布了一个解决方法 - Github repo typescript-subpath-exports-workaround。它使用exports和typeVersions
{
"main": "dist/index.js",
"types": "dist-types/index.d.ts",
"exports": {
".": "./dist/index.js",
"./exported": "./dist/exported.js"
},
"typesVersions": {
"*": {
"exported": ["dist-types/exported"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个新的反应应用程序(通过npx create-react-app命令)并尝试hello从中导入typescript-subpath-exports-workaround并且工作正常。但无法导入`typescript-subpath-exports-workaround/exported
import {hello} from "typescript-subpath-exports-workaround" //works fine
import {foo} from "typescript-subpath-exports-workaround/exported" //gives "Module not found" …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 Wordpress 网站上使用 OneDrive Excel 电子表格。到目前为止,如果有人通过桌面的互联网浏览器访问它,效果很好,但在移动设备上则无法正常工作。
我发现问题是,如果微软 javascript 将电子表格的单元格放在“div”标签中。移动浏览器不会将这些div识别为用于数据输入的东西,并且由于它不调用键盘,因此用户无法输入数据。
我可以使用 Javascript 或其他方法将这些 div 更改为其他将调用移动键盘的 html 标签吗?
请参考 microsoft OneDrive 的代码片段
<div id="myExcelDiv" style="width: 200px; height: 250px"></div>
<script type="text/javascript" src="http://r.office.microsoft.com/r/rlidExcelWLJS?v=1&kip=1"></script>
<script type="text/javascript">
var fileToken = "SDD03D60E1D5E574B7!119/-3441488017168698185/t=0&s=0&v=!ACF_FBbpHVUZBh8";
// run the Excel load handler on page load
if (window.attachEvent) {
window.attachEvent("onload", loadEwaOnPageLoad);
} else {
window.addEventListener("DOMContentLoaded", loadEwaOnPageLoad, false);
}
function loadEwaOnPageLoad() {
var props = {
item: "'Sheet1'!C4:D14",
uiOptions: {
showDownloadButton: false,
showGridlines: false,
showParametersTaskPane: false
},
interactivityOptions: {
allowParameterModification: false,
allowSorting: false, …Run Code Online (Sandbox Code Playgroud) 我使用Material-ui@next和 material-ui-next@next
material-ui@next加载一个图标用法:
import AddIcon from 'material-ui-icons/AddIcon';
function AddIconButton(props) {
return (
<AddIcon />
);
}
Run Code Online (Sandbox Code Playgroud)
但我想动态加载material-ci-icons图标
例如,我有可变菜单
const menus = [
{
Name: 'menu1',
Icons: 'face',
},
{
Name: 'menu2',
Icon: 'extension',
}
].
Run Code Online (Sandbox Code Playgroud)
如何根据菜单在页面上显示图标
我想在列上的 ant design 给出的“onFilter”属性中调用自定义函数。我可以选择自定义过滤器下拉列表作为选项,但我想使用 ant design 提供的默认过滤器选项。IE
\n{\n title: 'Address',\n dataIndex: 'address',\n key: 'address',\n filters: [{\n text: 'London',\n value: 'London',\n }, {\n text: 'New York',\n value: 'New York',\n }],\n onFilter: (value, record) => record.address.indexOf(value) === 0,\n}\nRun Code Online (Sandbox Code Playgroud)\n但我在这里唯一需要更改的是一个自定义函数(它将触发 api 调用并在 redux 状态中设置新数据,以便组件将重新渲染它自己),例如
\n{\n ...\n onFilter: (value, record) => this.getFilteredData(value),\n}\nRun Code Online (Sandbox Code Playgroud)\n但是当我这样做时,我得到了这个错误,这也很有意义。
\n\n\n警告: setState(\xe2\x80\xa6): 无法在现有状态转换期间更新\n
\n
因此,请指导我如何做到这一点,因为我对反应和蚂蚁设计都是新手。
\n使用 Ember.js 运行测试时出现以下错误:
承诺在“...”之前被拒绝:断言失败:fullName 必须是正确的全名
这个错误是什么意思?
我正在使用socket.io-client来获取加密货币的最新数据
constructor() {
super();
this.socket = openSocket('https://coincap.io');
}
Run Code Online (Sandbox Code Playgroud)
然后调用它componentDidMount
componentDidMount() {
this.socket.on('trades', (tradeMsg) => {
for (let i=0; i< this.updateCoinData.length; i++) {
console.log("it is being called still")
if (this.updateCoinData[i]["short"] == tradeMsg.coin ) {
this.updateCoinData[i]["price"] = tradeMsg["message"]['msg']['price']
//Update the crypto Value state in Redux
this.props.updateCrypto(this.updateCoinData);
}
}
})
Run Code Online (Sandbox Code Playgroud)
由于套接字已打开,因此它将继续发出消息。现在我想当我从一个屏幕导航到另一个屏幕时,套接字连接将断开,因此我正在做这样的事情
componentWillUnmount() {
this.socket.disconnect();
}
Run Code Online (Sandbox Code Playgroud)
但即使我已经导航到不同的页面,我的套接字仍在继续发出信号,这意味着它仍然处于连接状态。
我不确定这是否是因为react-navigation我在这里使用StackNavigator。
这是我的react-navigation组件
export const MyScreen = createStackNavigator({
Home: {
screen: CoinCap
},
CoinCapCharts: {
screen: CoinCapCharts
},
CurrencySelection: {
screen: …Run Code Online (Sandbox Code Playgroud) 我正在开发一个reactjs网站,我想让该网站即使在浏览器中禁用javascript时也能运行。是否可以?如何开发一个在两种条件(启用和禁用 Javascript)下运行的 React 站点,例如:fb、StackOverflow 甚至在禁用 javascript 的情况下仍在运行,这是怎么发生的?
运行 React 应用程序时,我在控制台中收到此错误 - 从 2021 年 5 月左右的 M91 开始,SharedArrayBuffer 将需要跨域隔离。有关更多信息,请参阅https://developer.chrome.com/blog/enabling-shared-array-buffer/细节。
根据 StackOverflow 的建议,我尝试更新 React 版本。我的版本是 16,后来切换到了 17。但是现在依赖树中存在冲突。当我尝试 npm install 时,出现以下错误:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR! react@"^17.0.2" from the root project
npm ERR! peer react@">=16.8.0" from @emotion/react@11.1.5
npm ERR! node_modules/@emotion/react
npm ERR! @emotion/react@"^11.1.1" from react-select@4.3.0
npm ERR! node_modules/react-select
npm ERR! react-select@"^4.2.1" from the root project
npm ERR! 17 more …Run Code Online (Sandbox Code Playgroud) 我正在使用react-responsive-carousel库。在这里,我想将默认指示器CSS、点形状更改为线形状。我的代码是,
<CarouselWrapper
sx={{ marginTop: "124px", maxHeight: "486px", minHeight: "150px" }}
>
<Carousel autoPlay infiniteLoop showArrows={false}>
<div>
<Image src={image1} />
</div>
<div>
<Image src={image1} />
</div>
<div>
<Image src={image1} />
</div>
</Carousel>
</CarouselWrapper>
Run Code Online (Sandbox Code Playgroud)
这些指标的当前形状,
是否可以自定义点形状指示器?
css responsive-design reactjs next.js react-responsive-carousel
reactjs ×8
javascript ×3
node.js ×2
antd ×1
browser ×1
css ×1
ember-qunit ×1
ember.js ×1
html ×1
jquery ×1
material-ui ×1
next.js ×1
noscript ×1
npm ×1
npm-install ×1
onedrive ×1
package.json ×1
react-native ×1
redux ×1
sockets ×1
typescript ×1
wordpress ×1