我知道现在不可能将你自己的CSS链接到喜欢的盒子来定制它,但是这个问题似乎可以使用类似的盒子向导完成.我想要做的就是将边框颜色更改为与我的页面背景相同,以便根本看不到边框.奇怪的是,看起来我放在边框区域的任何颜色都不会影响结果.这是我的网站:http://www.uplatindance.com/SDO/
这是嵌入式代码
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like-box" data-href="http://www.facebook.com/pages/Its-Salsa-Time/205870466141243" data-width="260" data-height= "65" data-colorscheme="dark" data-show-faces="false" data-border-color="black" data-stream="false" data-header="false"></div>
Run Code Online (Sandbox Code Playgroud)
思考?
我遇到了一个问题,其中我有一个无状态组件,它从 History 对象传递过来,react-router-dom并通过 props 将该对象传递给有状态对象。打字稿似乎不认为我可以将历史对象作为道具传递下去。
这是我的组件
import { History } from 'history';
import * as React from 'react';
import { RouteComponentProps, withRouter } from 'react-router-dom';
const SignInPage = ({ history }: { history: History }) =>
<div>
<h1>SignIn</h1>
<SignInForm history={history} />
</div>
class SignInForm extends React.Component<RouteComponentProps<{}>, {}> {
constructor(props: RouteComponentProps<{}>) {
super(props);
}
public handleClick = () => {
const { history } = this.props;
history.push('/home')
};
public render() {
return (
<button onClick={this.handleClick}>Sign In!</button>
);
}
} …Run Code Online (Sandbox Code Playgroud) 使用ssh2-sftp-client库从 SFTP 站点下载多个文件时出现错误。抛出的错误似乎表明每次下载完成后节点流都没有被清除。这导致我的应用程序出现内存泄漏。在生产中,我需要能够下载数千个文件,因此这种内存泄漏非常严重。如何关闭流以便在每个文件下载后释放内存?
代码:
const Client = require('ssh2-sftp-client');
const sftp = new Client();
sftp.connect({
host: '195.144.107.198',
port: 22,
username: 'demo',
password: 'password'
}).then(async () => {
const fileNames = ['readme.txt', 'readme.txt', 'readme.txt', 'readme.txt', 'readme.txt', 'readme.txt', 'readme.txt', 'readme.txt', 'readme.txt', 'readme.txt', 'readme.txt', 'readme.txt'];
// Loop through filenames
for (let i = 0; i < fileNames.length; i++) {
// Download all the files synchronously (1 at a time)
const fileName = fileNames[i];
await new Promise((resolve, reject) => { // <-- note …Run Code Online (Sandbox Code Playgroud) 是否可以在TypeScript中的接口声明中包含条件.我正在寻找的是一种方式,根据第一个键的值,第二个键可以是这些值.
示例(不起作用):
interface getSublistValue {
/** The internal ID of the sublist. */
sublistId: 'item' | 'partners';
/** The internal ID of a sublist field. */
if (this.sublistId === 'item') {
fieldId: 'itemname' | 'quantity';
}
if (this.sublistId === 'partners') {
fieldId: 'partnername' | 'location';
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的表单,其中以组件状态存储用户电子邮件,并使用onChange函数更新状态。发生了一件奇怪的事情,如果我的onChange函数使用一个函数更新状态,则每次键入时都会在控制台中出现两个错误。但是,如果使用对象更新状态,则不会出错。我相信建议使用函数更新,因此我很想知道为什么会出现这些错误。
我的组件:
import * as React from 'react';
import { FormGroup, Input, Label } from 'reactstrap';
interface IState {
email: string;
}
class SignUpForm extends React.Component<{}, IState> {
constructor(props: {}) {
super(props);
this.state = {
email: ''
};
}
public onEmailChange = (event: React.ChangeEvent<HTMLInputElement>) => {
this.setState(() => ({ email: event.currentTarget.value }))
};
// Using this function instead of the one above causes no errors
// public onEmailChange = (event: React.ChangeEvent<HTMLInputElement>) => {
// this.setState({ email: event.currentTarget.value })
// }; …Run Code Online (Sandbox Code Playgroud) 我想知道是否有可能从一个打字稿.d.ts文件中导出名称空间,然后将该名称空间导入另一个.d.ts文件中,以便在名称空间中使用它。
例:
namespace_export.d.ts
export namespace Foo {
interface foo {
prop1: string;
}
}
Run Code Online (Sandbox Code Playgroud)
类型
import { Foo } from './namespace_export'
export namespace Types {
Foo // <-- This doesn't work but is what I would like
interface Bar {
prop2: string
}
}
Run Code Online (Sandbox Code Playgroud)
测试文件
import { Types } from './types'
function testTypes(type: Types.Foo.foo) {
console.log(type);
}
Run Code Online (Sandbox Code Playgroud) 我有一个非常基本的有状态组件,我正在使用重构来向我的组件添加多个HOC(在我的示例中,我仅使用一个来简化).由于某些原因,打字稿给我一个关于我的道具进入我的组件的错误.我怎样才能摆脱这个错误?
这是我的代码:
import * as React from 'react';
import { connect } from 'react-redux';
import { compose } from 'recompose';
interface IStoreState {
readonly sessionState: {
authUser: { email: string; }
}
}
interface IAccountPageProps {
authUser: { email: string }
}
const AccountPage = ({ authUser }: IAccountPageProps ) =>
<div>
<h1>Account: {authUser.email}</h1>
</div>
const mapStateToProps = (state: IStoreState) => ({
authUser: state.sessionState.authUser,
});
export default compose(
connect(mapStateToProps)
)(AccountPage);
Run Code Online (Sandbox Code Playgroud)
而我得到的错误是:
Argument of type '({ authUser }: IAccountPageProps) => Element' …Run Code Online (Sandbox Code Playgroud) 当我在浏览器中生成 FCM 令牌时,我还将其发送到我的服务器,该服务器使用 firebase 管理模块订阅它的主题,如下所示:
messaging.subscribeToTopic(token, 'all')
我想知道如果我使用该方法删除浏览器中的令牌,messaging.deleteToken(currentToken)我是否还需要取消订阅在我的服务器上使用的相同令牌messaging.unsubscribeFromTopic(token, 'all');,或者在删除令牌时 firebase 是否会自动执行此操作?
我希望对放置在 pre 标签内的代码标签内的文本有滚动效果(从左到右)。我已经尝试了该overflow: scroll属性但没有成功。一个例子是这样的:
<pre><code>
var text = 'This is a bit of longer text that ends up wrapping around and messing up the rest of the formatting.';
var object {
text: text,
key: 'A second key with some more really long text that will overflow onto the next line',
}
</code></pre>
Run Code Online (Sandbox Code Playgroud)
我需要为我的代码元素提供什么样式以允许文本换行而不影响代码的格式?具有讽刺意味的是,堆栈溢出中的代码具有我正在寻找的效果,尽管我似乎无法复制它。
*我已经更新了问题,添加了代码位于保留换行符和格式的预标记中。
我正试图找到一种方法来检查函数参数是否是一个数组.如果不是,请将其转换为数组并对其执行功能,否则只需对其执行一项功能.
例:
interface employee {
first: string,
last: string
}
function updateEmployees (emp: employee | employee[]) {
let employees = [];
if (emp instanceof Array) employees = [emp];
else employees = emp;
employees.forEach(function(e){
return 'something'
})
}
Run Code Online (Sandbox Code Playgroud)
这似乎对我有用,但却发出警告 Type 'employee' is not assignable to type 'any[]'. Property 'length' is missing in type 'employee'.
不允许在高级组件内部使用挂钩吗?当我尝试使用这种简单模式进行操作时,出现错误Invalid hook call. Hooks can only be called inside of the body of a function component.
// App.js
import React, { useState } from 'react';
const WithState = (Component) => {
const [state, dispatch] = useState(0);
return () => <Component state={state} dispatch={dispatch} />;
}
const Counter = ({ state }) => {
return (
<div style={{ textAlign: 'center', margin: '0 auto'}}>
{state}
</div>
)
}
const CounterWithState = WithState(Counter);
const App = () => {
return <CounterWithState />;
} …Run Code Online (Sandbox Code Playgroud) javascript ×7
typescript ×6
reactjs ×4
arrays ×1
facebook ×1
firebase ×1
html ×1
namespaces ×1
node-streams ×1
node.js ×1
react-hooks ×1
recompose ×1
sftp ×1
word-wrap ×1